Promblem in GUI Error while evaluating DestroyedObject Callback

8 次查看(过去 30 天)
Error in matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)webcam1('exit_Callback',hObject,eventdata,guidata(hObject)) Error using imaqdevice/getdata (line 141) Error while evaluating DestroyedObject Callback
Error using matlab.ui.control.UIControl/set Invalid or deleted object. when press Exit

回答(1 个)

Geoff Hayes
Geoff Hayes 2017-6-24
Adisorn - did you press stop (in the GUI) before you pressed exit? If so, then (based on your code in the stop button callback) you do
set(handles.start, 'UserData', true);
In the realtimefunction, at the end of the while loop the code checks this value and exits the loop if set to true. In that case, the lines
stop(vid);
delete(vid);
clear vid;
clearvars svmStruct;
are executed which means your video object is no longer valid...which is the one that you reference in the exit callback
if isfield(handles, 'vid') && ~isempty(handles.vid)
stop(handles.vid); % or close, whatever is relevant
handles.vid = [];
guidata(hObject, handles)
end
Since handles.vid is no longer valid, then the error message Invalid or deleted object makes sense. So is the code in the exit callback necessary? Is it just there to handle the case where the user has pressed Exit without pressing Stop? If so, then I would just call the stop function callback from the exit callback which will do the same thing and stop the video object (via the realtimefunction) if needed
function exit_Callback(hObject, eventdata, handles)
stop_Callback(handles.stop, eventdata, handles);
set(handles.vid, []); % not really necessary since exiting the GUI now
guidata(hObject, handles);
I haven't tested the above, but I think that it will work. Perhaps you can remove handles.vid altogether?

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by