diff --git a/doomsday/libs/core/src/core/timer.cpp b/doomsday/libs/core/src/core/timer.cpp index 3cd13cb452..9e1af4ddb5 100644 --- a/doomsday/libs/core/src/core/timer.cpp +++ b/doomsday/libs/core/src/core/timer.cpp @@ -138,6 +138,17 @@ struct TimerScheduler : public Thread, public Lockable static LockableT scheduler; static std::atomic_int timerCount; // Number of timers in existence. + +static void deleteTimerScheduler() +{ + DE_GUARD(scheduler); + if (scheduler.value) + { + scheduler.value->stop(); + delete scheduler.value; + scheduler.value = nullptr; + } +} } // namespace internal @@ -148,19 +159,19 @@ DE_PIMPL_NOREF(Timer) bool isActive = false; std::atomic_bool isPending{false}; // posted but not executed yet - ~Impl() - { - using namespace internal; - - // The timer scheduler thread is stopped after all timers have been deleted. - DE_GUARD(scheduler); - if (--timerCount == 0) - { - scheduler.value->stop(); - delete scheduler.value; - scheduler.value = nullptr; - } - } +// ~Impl() +// { +// using namespace internal; +// +// // The timer scheduler thread is stopped after all timers have been deleted. +// DE_GUARD(scheduler); +// if (--timerCount == 0) +// { +// scheduler.value->stop(); +// delete scheduler.value; +// scheduler.value = nullptr; +// } +// } DE_PIMPL_AUDIENCE(Trigger) }; @@ -177,6 +188,7 @@ Timer::Timer() { scheduler.value = new TimerScheduler; scheduler.value->start(); + atexit(deleteTimerScheduler); } ++timerCount; }