Timer instance deleted but MATLAB thinks the timer is running

21 visualizaciones (últimos 30 días)
Mikulas Kostak
Mikulas Kostak el 24 de Mayo de 2022
Respondida: Shivang el 19 de Oct. de 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?

Respuestas (1)

Shivang
Shivang el 19 de Oct. de 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

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by