Closing GUI without error
11 views (last 30 days)
Show older comments
Denis Kartachov
on 2 Nov 2016
Commented: Image Analyst
on 2 Nov 2016
In my GUI I have a simulation that runs with a while loop. Problem is when I close the window while it's still running, matlab gives me an error message of the sort:
Error using matlab.ui.control.UIControl/get
Invalid or deleted object.
Error in SPCgui>startrestart_Callback (line 376)
if get(handles.pauseresume,'Value')==1
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in SPCgui (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)SPCgui('startrestart_Callback',hObject,eventdata,gu idata(hObject))
Error while evaluating DestroyedObject Callback
Is there a way to force a loop to stop when I close the window so that this error doesn't occur? I tried using figure1_DeleteFcn and figure1_CloseRequestFcn to no avail.
0 Comments
Accepted Answer
Image Analyst
on 2 Nov 2016
Maybe try hitting the Pause button (two vertical bars) on the tool ribbon and then click the Quit Debugging button (red square).
5 Comments
Image Analyst
on 2 Nov 2016
Well I think that loop was sort of running like its own process and when you deleted the handle, the loop kept running which caused the problems. I do something similar - I have a checkbox that I make visible when a lengthy loop starts that the user may wish to interrupt. The checkbox says "Finish Now" and the user checks it if they want to abort the loop. At the bottom of the loop I have
if handles.chkFinishNow.Value
break; % Bail out of loop.
end
After the loop exits, I set the value to 0/off and make the checkbox invisible.
An alternate with with a push button is attached as a small demo.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!