Skip to content

Commit 89284ab

Browse files
committed
Experimental fix for win32 timer syntax
1 parent 36664e2 commit 89284ab

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

JuceLibraryCode/modules/juce_core/native/juce_PlatformTimer_windows.cpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,37 @@ class PlatformTimer final
3939
};
4040

4141
timerId = timeSetEvent ((UINT) newIntervalMs, 1, callback, (DWORD_PTR) &listener, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
42-
intervalMs = timerId != 0 ? newIntervalMs : 0;
42+
const auto timerStarted = timerId != 0;
43+
44+
if (timerStarted)
45+
{
46+
intervalMs = newIntervalMs;
47+
return;
48+
}
49+
50+
if (fallbackTimer == nullptr)
51+
{
52+
// This assertion indicates that the creation of a high-resolution timer
53+
// failed, and the timer is falling back to a less accurate implementation.
54+
// Timer callbacks will still fire but the timing precision of the callbacks
55+
// will be significantly compromised!
56+
// The most likely reason for this is that more than the system limit of 16
57+
// HighResolutionTimers are trying to run simultaneously in the same process.
58+
// You may be able to reduce the number of HighResolutionTimer instances by
59+
// only creating one instance that is shared (see SharedResourcePointer).
60+
//
61+
// However, if this is a plugin running inside a host, other plugins could
62+
// be creating timers in the same process. In most cases it's best to find
63+
// an alternative approach than relying on the precision of any timer!
64+
#if ! JUCE_UNIT_TESTS
65+
jassertfalse;
66+
#endif
67+
68+
fallbackTimer = std::make_unique<GenericPlatformTimer> (listener);
69+
}
70+
71+
fallbackTimer->startTimer (newIntervalMs);
72+
intervalMs = fallbackTimer->getIntervalMs();
4373
}
4474

4575
void cancelTimer()

0 commit comments

Comments
 (0)