Skip to content
Permalink
Browse files

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: http://msdn.microsoft.com/en-us/library/windows/desktop/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
  • Loading branch information
slouken committed Mar 1, 2014
1 parent ab9345a commit e663b4eb76493b92e3218b1d4a55c4cadda8a5de

File 4 of 9 in e663b4e

@@ -27,19 +27,25 @@
static SDL_bool ticks_started = SDL_FALSE;

void
SDL_InitTicks(void)
SDL_TicksInit(void)
{
if (ticks_started) {
return;
}
ticks_started = SDL_TRUE;
}

void
SDL_TicksQuit(void)
{
ticks_started = SDL_FALSE;
}

Uint32
SDL_GetTicks(void)
{
if (!ticks_started) {
SDL_InitTicks();
SDL_TicksInit();
}

SDL_Unsupported();

0 comments on commit e663b4e

Please sign in to comment.