Wierd(?) problem with SDL_Delay

I’ve been working with SDL a while and have noticed
something I think might be peculiar (might be wrong on
this :slight_smile: ). I was trying to get a picture to stay up
on the screen for 10 seconds before fading off, my
problem is, when I call SDL_Delay to do this, the
program cannot be moved at all, it literally freezes
(can’t move the window what so ever). I thought
SDL_Delay just allowed windows to get to do somet
stuff (basically froze any SDL functions at the time)
but it also freezes my program. I’m curious if this
is normal and if so, would I be better of using
SDL_GetTicks and just looping for 10 seconds? Thanks
in advance!

Doug__________________________________
Do you Yahoo!?
Jazz up your holiday email with celebrity designs. Learn more.
http://celebrity.mail.yahoo.com

Doug Steele wrote:

I’ve been working with SDL a while and have noticed
something I think might be peculiar (might be wrong on
this :slight_smile: ). I was trying to get a picture to stay up
on the screen for 10 seconds before fading off, my
problem is, when I call SDL_Delay to do this, the
program cannot be moved at all, it literally freezes
(can’t move the window what so ever). I thought
SDL_Delay just allowed windows to get to do somet
stuff (basically froze any SDL functions at the time)
but it also freezes my program. I’m curious if this
is normal and if so, would I be better of using
SDL_GetTicks and just looping for 10 seconds? Thanks
in advance!

Doug

Yes. SDL_Delay is really just sleep(). It completely suspends the thread for that length of time.
If you use a busy loop instead, then that will use 100% CPU, and will still freeze if you don’t check events in the loop.
What you might do is set a timer to go in 10 seconds, and have the callback post a SDL_QUIT event.
Then you can just run a normal event loop using SDL_WaitEvent(), and you will get a SDL_QUIT event when it is time to close.

Alternatively, if you don’t want to depend on timer functionality, you can use something like this:

SDL_Event evt;
Uint32 endtime = SDL_GetTicks() + 10000;
while(SDL_GetTicks() < endtime)
{
while(SDL_PollEvent(&evt))
{
/* Handle event */
}
SDL_Delay(10);
}

This may look like a very crude way of doing things, but this is pretty much how SDL_WaitEvent() does it, except that it does not check for a timeout.

Chris E.
-------------- next part --------------
A non-text attachment was scrubbed…
Name: signature.asc
Type: application/pgp-signature
Size: 252 bytes
Desc: OpenPGP digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20041227/ab50d3dc/attachment.pgp