From abe651639a52e21e43262207f9feae230aa358f6 Mon Sep 17 00:00:00 2001 From: Edward Rudd Date: Thu, 2 May 2013 21:40:59 -0400 Subject: [PATCH] move Ticks initialization tracking to separate function and ensure it's called with SDL_VideoInit is called to init SDL instead of SDL_Init -- why do we even allow initialization w/o calling at least SDL_Init(0) ? --- src/SDL.c | 8 ++------ src/timer/SDL_timer.c | 12 ++++++++++++ src/timer/SDL_timer_c.h | 1 + src/video/SDL_video.c | 5 +++++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/SDL.c b/src/SDL.c index c0b87caba..a61c710a7 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -32,9 +32,9 @@ /* Initialization/Cleanup routines */ #if !SDL_TIMERS_DISABLED -extern void SDL_StartTicks(void); extern int SDL_TimerInit(void); extern void SDL_TimerQuit(void); +extern void SDL_InitTicks(void); #endif #if SDL_VIDEO_DRIVER_WINDOWS extern int SDL_HelperWindowCreate(void); @@ -43,7 +43,6 @@ extern int SDL_HelperWindowDestroy(void); /* The initialized subsystems */ -static Uint32 ticks_started = 0; static SDL_bool SDL_bInMainQuit = SDL_FALSE; static Uint8 SDL_SubsystemRefCount[ 32 ]; @@ -93,10 +92,7 @@ int SDL_InitSubSystem(Uint32 flags) { #if !SDL_TIMERS_DISABLED - if (!ticks_started) { - SDL_StartTicks(); - ticks_started = 1; - } + SDL_InitTicks(); #endif /* Initialize the timer subsystem */ diff --git a/src/timer/SDL_timer.c b/src/timer/SDL_timer.c index 60b3bdb12..5e542f083 100644 --- a/src/timer/SDL_timer.c +++ b/src/timer/SDL_timer.c @@ -26,6 +26,8 @@ #include "SDL_cpuinfo.h" #include "SDL_thread.h" +extern void SDL_StartTicks(void); + /* #define DEBUG_TIMERS */ typedef struct _SDL_Timer @@ -70,6 +72,16 @@ typedef struct { static SDL_TimerData SDL_timer_data; +static Uint32 ticks_started = 0; + +void +SDL_InitTicks(void) +{ + if (!ticks_started) { + SDL_StartTicks(); + ticks_started = 1; + } +} /* The idea here is that any thread might add a timer, but a single * thread manages the active timer queue, sorted by scheduling time. diff --git a/src/timer/SDL_timer_c.h b/src/timer/SDL_timer_c.h index 559b36404..c759bcd84 100644 --- a/src/timer/SDL_timer_c.h +++ b/src/timer/SDL_timer_c.h @@ -26,6 +26,7 @@ #define ROUND_RESOLUTION(X) \ (((X+TIMER_RESOLUTION-1)/TIMER_RESOLUTION)*TIMER_RESOLUTION) +extern void SDL_InitTicks(void); extern int SDL_TimerInit(void); extern void SDL_TimerQuit(void); diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 3739c6f80..959f19dc1 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -29,6 +29,7 @@ #include "SDL_pixels_c.h" #include "SDL_rect_c.h" #include "../events/SDL_events_c.h" +#include "../timer/SDL_timer_c.h" #if SDL_VIDEO_OPENGL #include "SDL_opengl.h" @@ -415,6 +416,10 @@ SDL_VideoInit(const char *driver_name) if (_this != NULL) { SDL_VideoQuit(); } + +#if !SDL_TIMERS_DISABLED + SDL_InitTicks(); +#endif /* Start the event loop */ if (SDL_StartEventLoop() < 0 ||