diff --git a/modules/juce_events/timers/juce_Timer.cpp b/modules/juce_events/timers/juce_Timer.cpp index 5a135e479d..0fee2b5be4 100644 --- a/modules/juce_events/timers/juce_Timer.cpp +++ b/modules/juce_events/timers/juce_Timer.cpp @@ -344,18 +344,24 @@ void JUCE_CALLTYPE Timer::callPendingTimersSynchronously() (*instance)->callTimersSynchronously(); } -struct LambdaInvoker final : private Timer +struct LambdaInvoker final : private Timer, + private DeletedAtShutdown { - LambdaInvoker (int milliseconds, std::function f) : function (f) + LambdaInvoker (int milliseconds, std::function f) + : function (std::move (f)) { startTimer (milliseconds); } - void timerCallback() override + ~LambdaInvoker() final { - auto f = function; + stopTimer(); + } + + void timerCallback() final + { + NullCheckedInvocation::invoke (function); delete this; - f(); } std::function function; @@ -365,7 +371,7 @@ struct LambdaInvoker final : private Timer void JUCE_CALLTYPE Timer::callAfterDelay (int milliseconds, std::function f) { - new LambdaInvoker (milliseconds, f); + new LambdaInvoker (milliseconds, std::move (f)); } } // namespace juce