Timer callback function return value

Hello,

I’m using sdl_addTimer to create a user event, and it works. However, I do not
want my callback function to be called again, as I only need this event once.
Please do not ask why, it’s just that way. I could remove the timer when I get
the event in the event loop, but the callback function could have been called
again.

However, addTimer callback functions return a value, ‘interval’, which means
when the timer will call this function again. If the callback function returns
zero or a negative value, it is not called again (as expected. It was that or a
nice error). What happens with the timer if I do that? Should I still kill the
timer when I get the user event?

Thank you!

Luis Anton <anton_canalis hotmail.com> writes:

Hello,

I’m using sdl_addTimer to create a user event, and it works. However, I do not
want my callback function to be called again, as I only need this event once.
Please do not ask why, it’s just that way. I could remove the timer when I get
the event in the event loop, but the callback function could have been called
again.

However, addTimer callback functions return a value, ‘interval’, which means
when the timer will call this function again. If the callback function returns
zero or a negative value, it is not called again (as expected. It was that or a
nice error). What happens with the timer if I do that? Should I still kill the
timer when I get the user event?

Thank you!

G’day,

By looking at the docs, it seems to me that if you schedule your timer to zero
(i.e. not operating) that doesn’t kill the timer. You’d still have to kill it
with SDL_RemoveTimer (which returns a boolean on success/fail - maybe capture
the return value once while debugging and see what it returns?).

I’m not sure using a negative number is all that wize, since the system is
dealing with Uint32’s. A negative number (for signed int) is, when made
unsigned, a really, really big positive number - meaning the timer will still
fire if your program is running for a few days or something. Mind you, I’d say
that by setting it to 0xFFFFFFFF (-1 made unsigned) will give your program
plenty of time to kill the timer before it fires again. For speed of execution,
I’d suggest using 0xFFFFFFFF instead of -1 since it doesn’t need to be converted.

HTH,
-J