Promblem in GUI Error while evaluating DestroyedObject Callback
조회 수: 3 (최근 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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165432/image.png)
댓글 수: 0
답변 (1개)
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?
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!