Matlab freeze when using a file dialog selection

I'm having a very frustrating problem that I can't seem to solve when using file selection dialogue.
Occaisionaly when I load a file selection dialogue from a button on a GUI (using 'uigetfile'), matlab freezes and can't be recovered. The only solution is to stop the process in windows closing matlab and anything that I was working on. I've also had the same issue when using 'uiputfile'.
The problem is not repeatable and appears to be random when it occurs. It doesn't seem to matter whether I've had matlab open for hours or shortly after opening.
The method that the button callback accesses is as follows, and as you can see I've tried to use some of the tricks already suggested on this community by inserting pause and drawnow. Unfortuantely neither of these has fixed the issue and it still randomly occurs.
%%Function to load existing data dictionary into the tool.
function LoadDD(obj, ~, ~)
% Go to the folder location of most recently accessed simulink
% model
try
NewPath=fileparts(get_param(bdroot, 'FileName'));
if ~strcmp('C:\Program Files\MATLAB\R2015b\toolbox\simulink\blocks\library', NewPath)...
&&~strcmp('C:\Program Files\MATLAB\R2015b\toolbox\stateflow\stateflow', NewPath)
obj.PathName = NewPath;
end
catch
end
drawnow;
pause(0.05); %This is to prevent matlab from hanging
[FileName,obj.PathName] = uigetfile('*.m','Select a model data dictionary', obj.PathName );
drawnow;
pause(0.05);
if FileName ==0
obj.PathName = 'C:\TEAM\PROJECTS\ControlSystemsSVN\Mathworks\';
return
end
% Do other stuff...
Has anyone had any experience with this issue, and found any proper solutions?
I'm using R2015b.

5 comentarios

Greg
Greg el 17 de Oct. de 2017
Both uigetfile and uiputfile are modal, are you sure they aren't just open in the background (covered by other windows)?
Yes, I'm absolutely sure.
Jan
Jan el 18 de Oct. de 2017
It seems like you work on a Windows with 64 bits? Did you modify the Java engine used by Matlab?
Hi, yes I'm using 64 bit windows, but I've not done anything with Java.
I have exactly the same problem but unfortunately I could not solve...

Iniciar sesión para comentar.

 Respuesta aceptada

Try to use the following command before uigetfile.
com.mathworks.mwswing.MJFileChooserPerPlatform.setUseSwingDialog(1)
Let me know.

6 comentarios

Justin
Justin el 27 de Feb. de 2019
Editada: Justin el 27 de Feb. de 2019
Hmmm, I had big problem in Matlab 2017b where about one time in five, uiputfile would cause Matlab to hang. The drawnow and pause(0.1) fix reduced the problem but did not eliminate it.
com.mathworks.mwswing.MJFileChooserPerPlatform.setUseSwingDialog(1) did fix it completely, although it opens a rather dated looking window.
When I google for more info on setUseSwingDialog virtually nothing comes up!
This has worked for me as well. Since putting this into the code I've not had any further instances of MATLAB hanging.
Thank you!
Eleanor Betton
Eleanor Betton el 10 de Sept. de 2020
I tried this in 2020a but am still getting a total freeze up.
This also works for me. I am using MATLAB R2018b. Thank you!
It worked for 2019b also. Thanks!
Didn't really help (Matlab 2020b). Only changed the appearance of the getfile dialog

Iniciar sesión para comentar.

Más respuestas (2)

Greg
Greg el 18 de Oct. de 2017

0 votos

I just had a very similar occurrence. In my case, MATLAB was not completely frozen (Editor, documentation still worked), but it was stuck in a "Busy" state for a long time. Turned out my License Manager host server was powered down, but my MATLAB session was still live.

1 comentario

Unfortuantely, this is not the same issue. Matlab is completely stuck, there's no busy indication or anything like that. The whole program has completely frozen and there's no solution other than stopping the process.

Iniciar sesión para comentar.

Yair Altman
Yair Altman el 19 de Oct. de 2017
Editada: Yair Altman el 19 de Oct. de 2017

0 votos

The reason and the solution are explained here: http://undocumentedmatlab.com/blog/solving-a-matlab-hang-problem
It seems that you're already using drawnow and pause(), so you sould simply increase the pause amount.

1 comentario

Hi, I've seen this hence what I've put in my code. I've tried using longer pauses, but the problem still randomly occurs. It would be useful if mathworks would fix the problem, rather than us having to put in unreliable work arounds.

Iniciar sesión para comentar.

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by