How to interrupt WaitEvent?

Does SDL_PushEvent can be used to interrupt SDL_WaitEvent ?
I need to interrupt SDL_WaitEvent in the timer callback
to call a function on a regular basis. This function makes some GL calls
and would like to refresh the screen even if no event (mouse/keyboard)
occur.
I tried:

Uint32 Callback(Uint32 interval, void* param)
{ SDL_Event event;
event.type= SDL_USEREVENT;
event.user.code= 1; // means it’s the callback who called PushEvent
SDL_PushEvent (&event);
return interval;
}
but that does not work.

What could I do ?

Thanks,
Christopher

What could I do ?

…don’t use SDL_WaitEvent(). It’s almost always what you DO NOT want to
use in a program.

try:

SDL_Event event;
while (!SDL_PollEvent(&event))
{
if (time_to_do_something_while_waiting_for_events())
do_something_while_waiting_for_events();
else
SDL_Delay(10); /* give up timeslices for other programs. */
}

/* lands here when there’s an event to handle. */

do_something_with_my_event(&event);

–ryan.

GAUTIER Christopher wrote:

Does SDL_PushEvent can be used to interrupt SDL_WaitEvent ?

kind of - WaitEvent polls the event queue in 10 ms intervals, so
PushEvent should be able to wake up a WaitEvent (but you get a latency
of up to 10ms)

[code snipped]

but that does not work.

it’s hard to tell from your incomplete code fragment

Answer for Ryan:
The idea is that I want to be sure the display is updated
every x msec. (x can be larger than 1000). I thought using SDL_WaitEvent
could save cpu usage instead of polling/SDL_Delay’ing. (the application is
not meant to be highly interactive). Maybe the gain is not worth it.

Answer for Mattias:

it’s hard to tell from your incomplete code fragment

While I was cut-pasting more code, I found the bug :slight_smile:
and it was not really a SDL-related one.
Sorry for the annoyance.On Sat, 8 Dec 2001, Mattias Engdegard wrote: