Commits

Anonymous committed ad8375e

fix time.delay and time.wait

Comments (0)

Files changed (2)

 # BREAK = change breaks existing code
 # BUG	= fixed a bug that was (or could have been) crashing
 
+Februrary 12, 2003
+	fix immediate returns for first time.delay and time.wait
+
 February 11, 2003
 	more OSX SDLmain.m patches from Andrew Straw
 
         int funcstart, delay;
         if(ticks <= 0)
             return 0;
-    
+
         if(!SDL_WasInit(SDL_INIT_TIMER))
 	{
 		if(SDL_InitSubSystem(SDL_INIT_TIMER))
+                {
 			RAISE(PyExc_SDLError, SDL_GetError());
                         return -1;
+                }
 	}
+
         funcstart = SDL_GetTicks();
-        
         if(ticks >= WORST_CLOCK_ACCURACY)
         {
             delay = (ticks - 2) - (ticks % WORST_CLOCK_ACCURACY);
                 Py_END_ALLOW_THREADS
             }
         }
-        
 	do{
 		delay = ticks - (SDL_GetTicks() - funcstart);	
         }while(delay > 0);
 	if(ticks < 0)
 		ticks = 0;
 
-        return PyInt_FromLong(accurate_delay(ticks));
+        ticks = accurate_delay(ticks);
+        if(ticks == -1)
+            return NULL;
+        return PyInt_FromLong(ticks);
 }
 
 
 	if(!PyInt_Check(arg0))
 		return RAISE(PyExc_TypeError, "delay requires one integer argument");
 
+        if(!SDL_WasInit(SDL_INIT_TIMER))
+	{
+		if(SDL_InitSubSystem(SDL_INIT_TIMER))
+                {
+			RAISE(PyExc_SDLError, SDL_GetError());
+                        return NULL;
+                }
+	}
+
+        
 	ticks = PyInt_AsLong(arg0);
 	if(ticks < 0)
 		ticks = 0;
             int delay, endtime = (int)((1.0f/framerate) * 1000.0f);
             clock->rawpassed = SDL_GetTicks() - clock->last_tick;
             delay = endtime - clock->rawpassed;
+            delay = accurate_delay(delay);
+            if(delay == -1)
+                return NULL;
             accurate_delay(delay);
         }