Skip to content

Commit

Permalink
Experimental fix for win32 timer syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
jonoomph committed Dec 8, 2024
1 parent 36664e2 commit 89284ab
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,37 @@ class PlatformTimer final
};

timerId = timeSetEvent ((UINT) newIntervalMs, 1, callback, (DWORD_PTR) &listener, TIME_PERIODIC | TIME_CALLBACK_FUNCTION);
intervalMs = timerId != 0 ? newIntervalMs : 0;
const auto timerStarted = timerId != 0;

if (timerStarted)
{
intervalMs = newIntervalMs;
return;
}

if (fallbackTimer == nullptr)
{
// This assertion indicates that the creation of a high-resolution timer
// failed, and the timer is falling back to a less accurate implementation.
// Timer callbacks will still fire but the timing precision of the callbacks
// will be significantly compromised!
// The most likely reason for this is that more than the system limit of 16
// HighResolutionTimers are trying to run simultaneously in the same process.
// You may be able to reduce the number of HighResolutionTimer instances by
// only creating one instance that is shared (see SharedResourcePointer).
//
// However, if this is a plugin running inside a host, other plugins could
// be creating timers in the same process. In most cases it's best to find
// an alternative approach than relying on the precision of any timer!
#if ! JUCE_UNIT_TESTS
jassertfalse;
#endif

fallbackTimer = std::make_unique<GenericPlatformTimer> (listener);
}

fallbackTimer->startTimer (newIntervalMs);
intervalMs = fallbackTimer->getIntervalMs();
}

void cancelTimer()
Expand Down

0 comments on commit 89284ab

Please sign in to comment.