Timer instance deleted but MATLAB thinks the timer is running

21 次查看(过去 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?

回答(1 个)

Shivang
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

类别

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

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by