Filter löschen
Filter löschen

Timer instance deleted but MATLAB thinks the timer is running

8 Ansichten (letzte 30 Tage)
Mikulas Kostak
Mikulas Kostak am 24 Mai 2022
Beantwortet: Shivang am 19 Okt. 2023
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?

Antworten (1)

Shivang
Shivang am 19 Okt. 2023
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

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by