[SDL] Not Response on Window Mode (on WindowsXP)

David Olofson david at olofson.net
Sat Nov 12 11:16:28 PST 2005


On Saturday 12 November 2005 15.51, Wutipong Wongsakuldej wrote:
[...]
> I've changed to this :-
> 
> int UpdateScreen(void* data)
> {
>     static long exframe = SDL_GetTicks();
>     while(true)
>     {
>         //Delay each frame for approx 33ms
>         //SDL_Delay(33);
> 
>         //Start Render new Frame

------------------------------------
>         SDL_LockMutex(mutex);
------------------------------------

What's this mutex about? You're not by any chance trying to lock it 
(indirectly) from inside the ActionPerformed() method you're passing 
events to...?


>         long now = SDL_GetTicks();
> 
>         if(now-exframe >=33)
>         {
>             exframe = now;
> 
>             //Clear Frame Buffer
>             SDL_FillRect(backBuffer,NULL,0xffffffff);
>             //Draw Text to Screen
>             SDL_BlitSurface(background,NULL,backBuffer,NULL);
>             box->Draw(backBuffer);
>             SDL_BlitSurface(messageBuffer,NULL,backBuffer,NULL);
>             //Flip Frame Buffer
>             SDL_Flip(backBuffer);
>             //Do Event
>             SDL_Event event;
>             while(SDL_PollEvent(&event)==1)
>             {
>                 box->ActionPerformed(event);
>             };
>         }
>         SDL_UnlockMutex(mutex);
>         //Finish Render Frame

------------------------------------
>         SDL_Delay(0);
------------------------------------

Note that this SDL_Delay(0) will only work on Windows. There, it's 
equivalent to Un*x sched_yield() (give up the CPU to other runable 
threads, if any) - but on Un*x (POSIX API), it has no effect 
whatsoever.

Also note that unless you're using a driver that's (IMHO) broken or 
misconfigured to ignore retrace sync, you should not add any delays 
like this. SDL_Flip() is where the rendering thread should go to 
sleep, waiting for the driver to let go of the back buffer - but 
unfortunately, you have to deal with the case where this does not 
happen. I strongly recommend implementing a user configurable frame 
rate throttling feature.


[...]
> And the result is still the same (I mean, window is not movable, and 
> become not respond).

That's the exact symptoms of ignoring Win32 messages, so it does 
indeed seem like SDL_PollEvent() isn't getting called regularly, if 
at all.


//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
|  Free/Open Source audio engine for games and multimedia.  |
| MIDI, modular synthesis, real time effects, scripting,... |
`-----------------------------------> http://audiality.org -'
   --- http://olofson.net --- http://www.reologica.se ---




More information about the SDL mailing list