App desiner GUI crashes when use scatter3

Hi,
i have a problem with app designer and scatter3.
When I use scatter3 specifying the color for each point, the app crashes without giving any errors.
This is the line that causes the app to unexpectedly close:
scatter3 (app.UIAxes_GL_3D, ROI_coord(:, 1), ROI_coord(: 2), ROI_coord(:, 3), 1, color_matrix);
ROI_coord is a matrix of 22375x3 double, color_matrix is a matrix of 22375x3 double (with values between 0 and 1), UIAxes_GL_3D is the app axis.
I tried to use fewer points and in that case everything works fine.
I use Matlab version 2020a.
Why does this happen?
Thank you,
Davide

Answers (2)

Adam Danz
Adam Danz on 10 Feb 2021
Edited: Adam Danz on 11 Feb 2021
I've reproduced the problem using Matlab Online with the code below (commented-out to discourage people from trying it). Matlab Online crashes and throws an error in Chrome: Error code: Out of Memory
But this shouldn't cause Matlab to crash. It should just throw an error. I encourage you to report the problem: Contact Us - MATLAB & Simulink
% This will crash Matlab (Matlab Online 2020b)
% ROI_coord = rand(22375,3);
% color_matrix = rand(22375,3);
%
% app.UIAxes_GL_3D = uiaxes();
% scatter3 (app.UIAxes_GL_3D, ROI_coord(:, 1), ROI_coord(:, 2), ROI_coord(:, 3), 1, color_matrix);
There may be other ways to plot your data that don't involve storing 22375 graphics objects. Without knowing more about the intended visualization, it's tough to make suggestions.
Update I
Without the color_matrix, the scatter plot is created without a problem.
Update II
I traced the problem in scatter3() and it crashes when the CData property is set (the color matrix). Even if you set the CData after the plot is generated, it will still crash (see below).
ROI_coord = rand(22375,3);
color_matrix = rand(22375,3);
app.UIAxes_GL_3D = uiaxes();
h = scatter3 (app.UIAxes_GL_3D, ROI_coord(:, 1), ROI_coord(:, 2), ROI_coord(:, 3), 1);
% crash here:
% h.CData = color_matrix;
Update III
None of these problems happen with Matlab r2020b (update 4) on Microsoft Windows 10.
Workaround ideas
If there is color grouping, use indexing to plot each group separately using plot3() or scatter3(). dr
You could try using color indexing rather than defining the RGB value matrix. That's covered the documentation.
If each point varies in color, you might be able to visualize the data using another form such as a controur or surface. Perhaps you could reduce the density of data and plot custers using kmeans or another clustering method.

16 Comments

Hi Adam, thanks for the support.
I have 16 GB of RAM, I don't think that limit is reached. In fact, if I try to make a figure with the exact same data, I have no problem (In truth I can do dozens of identical ones without reaching any limits).
I also add that if I remove color_matrix, it works.
What do you say?
I was just messing around with it further and also found that removing color_matrix eliminated the crash.
Do you have groups of colors or are each point a completely different color?
If you have groups of colors you can plot each group separately which will likely solve the problem.
Davide P
Davide P on 10 Feb 2021
Edited: Davide P on 10 Feb 2021
Unfortunately the colors are not groupable (they are the projection of a 2D image on 3D points). However, I tried to add 1000 points at a time inside a loop, and in this way there is no crash (why this appen?). However, the solution is not satisfactory for these reasons:
- creation is however slower, due to the cycle;
- once visible on the app axis, it is practically unusable: it must be slowed down so much that it is almost impossible to rotate.
What I don't understand is why none of this happens if a figure is created instead of using the app.
So, as you noticed, all of these problems are due to the color part (which is why I use scatter3). In fact, by removing the color, crashes and slowdowns disappear. However, if you perform the equivalent operation in simple figure these problems do not exist.
P.S. Tomorrow I'll try to see if anything comes out of the logs, but I have my doubts.
> once visible on the app axis, it is practically unusable: it must be slowed down so much that it is almost impossible to rotate
That points to memory overflow (see this question, this Q/A,and documentation).
> they are the projection of a 2D image on 3D points
Perhaps you could visualize the 3D data with scatter3() using a single color and then visualize the 2D image using imagesc() or contourf() plotted on the same axis, under the scatter points. Here are some demos of similar approaches
> What I don't understand is why none of this happens if a figure is created instead of using the app.
Not sure what this means. I tried the reproducible demo in my answer using figure() and axes() instead of uifigure/uiaxes and the problem persists.
> I'll try to see if anything comes out of the logs, but I have my doubts
I'd be intertested in what you find. I've been testing it on Matlab Online and haven't looked into whether those logs are available online. Either way, I think it's something to be reported to tech support.
btw, I tried using color indexing and it crashes as well.
% This will crash Matlab (Matlab Online 2020b)
% ROI_coord = rand(22375,3);
% color_matrix = randi(5,22375,1); % <--- color index
%
% app.UIAxes_GL_3D = uiaxes();
% scatter3 (app.UIAxes_GL_3D, ROI_coord(:, 1), ROI_coord(:, 2), ROI_coord(:, 3), 1, color_matrix);
Hi Adam,
comment below what you told me:
> "That points to memory overflow (see this question, this Q/A,and documentation). "
I don't think it's a memory problem, because I looked and the occupied memory doesn't grow and has 40% of the 16GB free when it crashes. Also, Matlab should report the problem if there was one.
> "Not sure what this means. I tried the reproducible demo in my answer using figure() and axes() instead of uifigure/uiaxes and the problem persists. "
What I mean is, if you just try this, everything works great and fast:
ROI_coord = rand(22375,3);
color_matrix = rand(22375,3);
figure();
ax1=axes();
h = scatter3 (ax1, ROI_coord(:, 1), ROI_coord(:, 2), ROI_coord(:, 3), 1,color_matrix );
This is the result I get immediately and without problems:
> "I'd be intertested in what you find. I've been testing it on Matlab Online and haven't looked into whether those logs are available online. Either way, I think it's something to be reported to tech support."
Unfortunately I looked in the log folder (as explained in the link you put me) and the files are not there. Even the extractCrashLogs tool does not return any logs to me. The point, in my opinion, is that it is not Matlab that crashes, it is only the App (i mean the GUI opened with Appdesigner) that closes unexpectedly.
The only thing I can put you is the Windows log reporting the error (sorry it's in Italian):
Basically the error is simply attributed to: MATLABWindow.exe.
Do you have any other advice?
Thanks for the support anyway.
When I run the example you gave using regular figures using Matlab Online which uses release r2020b, it definitely crashes:
ROI_coord = rand(22375,3);
color_matrix = rand(22375,3);
figure();
ax1=axes();
h = scatter3 (ax1, ROI_coord(:, 1), ROI_coord(:, 2), ROI_coord(:, 3), 1,color_matrix );
I can't test it on my local software because I'm using it for multiple projects at the moment. I see you're using r2020a so the different may be due to the release or the system (Matlab Online uses Linux).
Have you reported this to Tech Support?
I use Matlab 2020a on Windows 10. More than the system, it may be that it is the online version which may have a different behavior. When and if you have time to test it directly on your machine, let me know you get it.
I opened a support ticket, we hope they let me know as soon as possible.
Thanks again for the help.
I've tested in with r2020b (update 4) Microsoft Windows 10 and there are no problems with using figure or uifigure/uiaxes.
So, here's what we know:
figure/axes uifigure/uiaxes
2020a: OK crash
2020b OK OK
2020b online: crash crash
Just out of curiosity in your report to tech support did you point to this conversation or tell them about the problems with Matlab online? They should know about that.
Yes to the support request I put the link to this conversation.
They have already replied that for now they confirm that the problem occurs both in 2020a and in 2020b (strange that 2020b works for you instead).
They told me that in 2021 prerelease it would seem not to happen. However they will continue to investigate the issue and let me know.
I can't make it work on 2020b either.
Hi Veronica,
as I explain in the answer I put below, in the 2020b version it only works by setting a different render engine, but as it says, however, it is not conclusive. Check out my explanation, it's a bug they're working on now after my report.
Hi Davide, I already read your answer, thank you. My intention by replying was to point out that one more person is hoping to fix it . I don't know how it works on Mathworks community, I thought the more feedback they have, the sooner they decide to work on it (more people asking = feature greatly required = priority for the team).
[I am working on point cloud on GUI, both pcshow and scatter3 have trouble, I am going to try plot3 but I already know I will have other issue (due to my specific workflow I mean). Thank you, bye]
Ok, no problem. I had to do some GUI with Matlab and actually there are often problems. We hope they improve.

Sign in to comment.

I have updates from support: has been confirmed as a bug currently present
Cause of the problem: the problem is related to the render engine "It is an internal memory issue when interacting with Chromium windows specifically, which is why the behavior is observable with Apps and UIFigures but not with the standard Java based figure."
I immediately say that the definitive solution does not yet exist. It's only partially solved in the 2021a prerelease.
There are possible wokarounds. I put them here because maybe someone could be useful for actual release.
  • In 2020a and 2020b versions: you have to try to switch to an alternative render engine, so depending on the one set, you have to try to use one of these two commands:
> from the Windows Command Prompt using:
matlab -softwareopenglmesa
> executing the following in the MATLAB Command Window:
>> opengl software
I tried with "matlab -softwareopenglmesa" and I was able to visualize the points within UIAxes. However, for me the solution is not optimal because in any case there is a heavy slowdown in the rotation of the points and above all it is an impractical solution because it depends on the PC on which the App is running.
  • In the 2021a preprelease version the problem is mitigated (but not completely solved) because it uses a different version of Chromium. Use in that case:
s = scatter3 (app.UIAxes_GL_3D, ROI_coord (:, 1), ROI_coord (:, 2), ROI_coord (:, 3), 1, color_matrix, 'PickableParts', 'none');
PickableParts was introduced in 2021 and works to mitigate the problem.
Obviously I was told that the development team will look for a definitive solution that will be included in the code as soon as it is ready.

Categories

Find more on Environment and Settings in Help Center and File Exchange

Products

Release

R2020a

Asked:

on 10 Feb 2021

Commented:

on 25 Feb 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!