- https://www.mathworks.com/help/matlab/ref/handle.isvalid.html
- https://www.mathworks.com/help/matlab/ref/timer.stop.html
Timer instance deleted but MATLAB thinks the timer is running
8 次查看(过去 30 天)
显示 更早的评论
I have been making a chromatic tuner (for a school project) and everything is running pretty okay but there's one issue. I am using the timer to invoke a procedure that records some short recording and extracts frequency from it. After closing the figure (I have the tuner on) callback function is called to clean up, i. e. to stop the ticker and exit the program safely.
Underneath follows the function.
function safeClose(src, event)
%SAFECLOSE Safely closes and terminates everything
ticker = getappdata(src, "recTicker");
ticker.stop();
delete(ticker);
delete(src);
end
I do this but when MATLAB is doing his own cleanup he runs into a running timer (or at least it looks like that) and says
Invalid or deleted object.
Error in timer/timercb (line 126)
obj.errorReachedMsgId = exception.identifier;
Does anybody have idea how to solve this issue?
0 个评论
回答(1 个)
Shivang
2023-10-19
Hi Mikulas,
I understand you're running into an error while trying to stop and delete a timer object.
The error states that the timer object you're trying to stop or delete has an invalid handle. Before working with the timer object, you can check whether its handle is valid using the "isvalid" function. You can further check if the "Running" property of the timer object is set to 'on' before trying to stop it.
if isvalid(ticker)
if strcmp(ticker.Running,'on')
stop(ticker);
end
delete(ticker);
end
Refer to these documentation links for more details:
Hope this helps.
Regards,
Shivang
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!