Timer callback pushing an event!?

Hrm… I’d like my program to sit pretty much idle until the
timer goes off. So in my main loop, I’ll be doing an
"SDL_WaitEvent()".

When the timer goes off, I need to let the main loop know to wake up
and smell the SDL_USEREVENT I’m sending it…

However, from the docs:

“The timer callback function may run in a different thread than your main
program, and so shouldn’t call any functions from within itself.”

This means that I really shouldn’t be using “SDL_PushEvent()” in my
callback function.

So… how do I do this? Should I just switch to “SDL_PollEvent()” and
have the main loop run /mostly/ idle (by using a large SDL_Delay())???

-bill!

Hrm… I’d like my program to sit pretty much idle until the
timer goes off. So in my main loop, I’ll be doing an
"SDL_WaitEvent()".

When the timer goes off, I need to let the main loop know to wake up
and smell the SDL_USEREVENT I’m sending it…

However, from the docs:

“The timer callback function may run in a different thread than your main
program, and so shouldn’t call any functions from within itself.”

Since SDL_PushEvent() is thread-safe, you can call it from within your
timer function. :slight_smile:

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software