Fixed bug 2423 - timeBeginPeriod & timeEndPeriod mismatch

Coriiander

In src\timer\windows\SDL_systimer.c there is an error with regards to timeBeginPeriod and timeEndPeriod. These functions typically get called when no high resolution timer is available, and GetTickCount is not used.

According to MSDN (link: dd757624(v=vs.85).aspx), for every call to timeBeginPeriod a subsequent call to timeEndPeriod is required. While SDL is currently doing this, it fails to call timeEndPeriod when cleaning up/shutting down SDL. Please note that these functions affect things on a system level. Failing to call timeEndPeriod, disables applications for using WINMM-timers after usage&shutdown of SDL, as effectively they the mechanism is now broken.

Solution:
Ensure this code gets called when shutting down the timer subsystem:

#ifndef USE_GETTICKCOUNT
if (!hires_timer_available)
{
    timeSetPeriod(0);
}
#endif
This commit is contained in:
Sam Lantinga 2014-03-01 09:50:52 -08:00
parent cff6eb5155
commit b7435a3ad3
9 changed files with 68 additions and 20 deletions

View file

@ -40,7 +40,6 @@ static BOOL hires_timer_available;
static LARGE_INTEGER hires_start_ticks;
/* The number of ticks per second of the high-resolution performance counter */
static LARGE_INTEGER hires_ticks_per_second;
#endif
static void
timeSetPeriod(UINT uPeriod)
@ -76,13 +75,15 @@ SDL_TimerResolutionChanged(void *userdata, const char *name, const char *oldValu
}
}
#endif /* !USE_GETTICKCOUNT */
void
SDL_InitTicks(void)
SDL_TicksInit(void)
{
if (ticks_started) {
return;
}
ticks_started = TRUE;
ticks_started = SDL_TRUE;
/* Set first ticks value */
#ifdef USE_GETTICKCOUNT
@ -98,11 +99,26 @@ SDL_InitTicks(void)
hires_timer_available = FALSE;
timeSetPeriod(1); /* use 1 ms timer precision */
start = timeGetTime();
SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
SDL_TimerResolutionChanged, NULL);
}
#endif
}
void
SDL_TicksQuit(void)
{
#ifndef USE_GETTICKCOUNT
if (!hires_timer_available) {
SDL_DelHintCallback(SDL_HINT_TIMER_RESOLUTION,
SDL_TimerResolutionChanged, NULL);
timeSetPeriod(0);
}
#endif
SDL_AddHintCallback(SDL_HINT_TIMER_RESOLUTION,
SDL_TimerResolutionChanged, NULL);
ticks_started = SDL_FALSE;
}
Uint32
@ -114,7 +130,7 @@ SDL_GetTicks(void)
#endif
if (!ticks_started) {
SDL_InitTicks();
SDL_TicksInit();
}
#ifdef USE_GETTICKCOUNT