[SDL] MouseMove events + long taking poll loop = infinite loop

RodrigoCard cuecax at gmail.com
Wed Sep 24 19:34:05 PDT 2014


mr_tawan wrote:
> Separate the event handler into another thread might helps a little, but it would create the synchronization complexity :).
> 
> There's another thing I can think of, which is just to poll the events in the loop, store in a queue, and then process them one by one outside of the event polling loop. 
> 
> Anyway if the processing an event takes 500ms (0.5 seconds) then there's some problem in that processing I believe. Especially when the event processing is inside the rendering loop, as it would hit the frame rate quite a lot. I think if the event processing takes an appropriate time then the infinite loop wouldn't occurs.


It is NOT a good idea to put a delay inside the event processing loop.
Instead, let the loop run as fast as possible and put the delay after that.

int running = 1;
while (running) {
  while( SDL_PollEvent( &e ) != 0 ) {
    //print/handle event
  } 
  SDL_Delay(500);
}

and the set running to 0 when you want it to break the outer loop.
Also, I dont know why you want a 500ms delay, but I think you should look to do this instead:

int running = 1;
while (running) {
  while( SDL_WaitEvent( &e ) != 0 ) {
    //print/handle event
  } 
  SDL_Delay(10); // or 1 or wherever
}

------------------------
Rodrigo Cardoso Rocha
@RodrigoRodrigoR - twitter.com/RodrigoRodrigoR
Chibata Creations - chibatacreations.com




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20140925/63deb1fb/attachment-0001.htm>


More information about the SDL mailing list