Borrar filtros
Borrar filtros

Promblem in GUI Error while evaluating DestroyedObject Callback

4 visualizaciones (últimos 30 días)
Adisorn Phanukthong
Adisorn Phanukthong el 23 de Jun. de 2017
Respondida: Geoff Hayes el 24 de Jun. de 2017
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

Respuestas (1)

Geoff Hayes
Geoff Hayes el 24 de Jun. de 2017
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?

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by