move Ticks initialization tracking to separate function and ensure it's called with SDL_VideoInit is called to init SDL instead of SDL_Init
authorEdward Rudd <urkle@outoforder.cc>
Thu, 02 May 2013 21:40:59 -0400
changeset 7139 dd722e7460c5
parent 7138 52ba4fa156c7
child 7140 e1896b95a8a7
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
src/timer/SDL_timer.c
src/timer/SDL_timer_c.h
src/video/SDL_video.c
--- a/src/SDL.c	Thu May 02 21:23:38 2013 -0400
+++ b/src/SDL.c	Thu May 02 21:40:59 2013 -0400
@@ -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 @@
 
 
 /* The initialized subsystems */
-static Uint32 ticks_started = 0;
 static SDL_bool SDL_bInMainQuit = SDL_FALSE;
 static Uint8 SDL_SubsystemRefCount[ 32 ];
 
@@ -93,10 +92,7 @@
 SDL_InitSubSystem(Uint32 flags)
 {
 #if !SDL_TIMERS_DISABLED
-    if (!ticks_started) {
-        SDL_StartTicks();
-        ticks_started = 1;
-    }
+    SDL_InitTicks();
 #endif
 
     /* Initialize the timer subsystem */
--- a/src/timer/SDL_timer.c	Thu May 02 21:23:38 2013 -0400
+++ b/src/timer/SDL_timer.c	Thu May 02 21:40:59 2013 -0400
@@ -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 @@
 
 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.
--- a/src/timer/SDL_timer_c.h	Thu May 02 21:23:38 2013 -0400
+++ b/src/timer/SDL_timer_c.h	Thu May 02 21:40:59 2013 -0400
@@ -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);
 
--- a/src/video/SDL_video.c	Thu May 02 21:23:38 2013 -0400
+++ b/src/video/SDL_video.c	Thu May 02 21:40:59 2013 -0400
@@ -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 @@
     if (_this != NULL) {
         SDL_VideoQuit();
     }
+    
+#if !SDL_TIMERS_DISABLED
+    SDL_InitTicks();
+#endif
 
     /* Start the event loop */
     if (SDL_StartEventLoop() < 0 ||