matlab3dmcc

3D rotation slow when compiling with mcc R2015b


I'm experiencing a strange issue when compiling one of my application with mcc compiler deployed with R2015b, the rotation of 3D views (i.e. using rotate3D button in toolbar) is now extremely slow which was not the case when compiling exactly the same code with R2013b. When running the application either in R2013b or R2015b environements the rotation is really fluid/smooth in both cases.

I tried a much simpler code equivalent to 3D I have in my application:

function [] = TestCompiledRotationR2015b()
%[
    % Create random data
    azimuths = linspace(0, 359, 360) * pi / 180;
    elevations = linspace(0, 180, 181) * pi / 180;
    [A, E] = ndgrid(azimuths, elevations);
    Data = sin(7*(E-pi/2))./(7*(E-pi/2));
    Data(isnan(Data)) = 1;
    Data = Data .* abs(cos(0.5*A));

    ff = figure(42);
    X = cos(A) .* sin(E);
    Y = sin(A) .* sin(E);
    Z = cos(E);
    surf(X, Y, Z, abs(Data));

    % Set axes properties
    shading flat;   
    set(gca, 'DataAspectRatio', [1 1 1]);
    set(gca, 'Visible', 'off');
    xlim([-1 1]);
    ylim([-1 1]);
    zlim([-1 1]);

    uiwait(ff);
%]

I also tried with more complex one (using GUI layout panels and cards which I use a lot in my application) .... I logged 'renderer' details just in case (both opengl fully hardware accelerated in compiled and non compiled modes) ... but failed to reproduce slow rotation I have in my compiled application.

So here, I'm just wondering if any of you is experimenting same issue (3D slow only when compiled with R2015b and for some applications only) ... I think there's something wrong I'm doing, but why it was working in R2013b and why is it still ok in R2015b environment (i.e. not compiled ... only compiled R2015b is causing issue) is a full mystery.

** Edit **

I tried activating the profiler while moving the mouse for about 1 minute for both compiled and not compiled modes, nothing special except the refreshing rate which decrease drastically in compiled mode (~160 calls in compiled mode versus 4100 calls in environment mode)

Profiler


Solution

  • Ok, after many tests, it all appears that the issue is linked to the fact that I'm running the matlab code from a C# application designed for use in system tray:

    All following tests are ok:

    Only calling 'csharedlib' from system tray c# app causes issue. I tried designing much simpler system tray application and it works fine, so it's nobody's fault but mine and need to fix call to matlab code (probably in wrong thread or wrongly parented to receive mouse events).

    Issue closed.