From 15d746cf6edf25e8337725483741d4041bebf348 Mon Sep 17 00:00:00 2001 From: jules Date: Fri, 12 Feb 2016 11:36:34 +0000 Subject: [PATCH] Added a safety mechanism for pathological cases where user code that repeatedly blocks in a timer callback could get the event loop stuck --- modules/juce_events/timers/juce_Timer.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/modules/juce_events/timers/juce_Timer.cpp b/modules/juce_events/timers/juce_Timer.cpp index 61b60b7419..e2be686eda 100644 --- a/modules/juce_events/timers/juce_Timer.cpp +++ b/modules/juce_events/timers/juce_Timer.cpp @@ -92,6 +92,9 @@ public: void callTimers() { + // avoid getting stuck in a loop if a timer callback repeatedly takes too long + const uint32 timeout = Time::getMillisecondCounter() + 100; + const LockType::ScopedLockType sl (lock); while (firstTimer != nullptr && firstTimer->timerCountdownMs <= 0) @@ -109,6 +112,9 @@ public: t->timerCallback(); } JUCE_CATCH_EXCEPTION + + if (Time::getMillisecondCounter() > timeout) + break; } callbackArrived.signal();