Timer instance deleted but MATLAB thinks the timer is running

14 ビュー (過去 30 日間)
Mikulas Kostak
Mikulas Kostak 2022 年 5 月 24 日
回答済み: Shivang 2023 年 10 月 19 日
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 Center および File ExchangeGet Started with Optimization Toolbox についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by