bmisiak/samp-precise-timers

Question

Closed this issue · 1 comments

possible to add in the next version of the plugin native IsValidPreciseTimer(timerid); ?
for pawno code use the code bug

#define INVALID_TIMER_ID (0xFFFF)
IsValidPreciseTimer(timerid){
if(timerid != INVALID_TIMER_ID) return 1;
return 0;
}

This function, though present on other plugins, is kind of an illusion. Hypothetically, if you have a timer and you save its ID in variable gMyTimer, then delete the timer without zeroing out the variable, at some point in the future a new timer might receive the same ID. At that point, calling IsValidPreciseTimer(gMyTimer) would return true even though it would actually be pointing to a completely different timer. If you tried to delete it by that ID, you would delete the wrong timer entirely.

So I would say make sure you keep track of timers on your side rather than relying on IsValidTimer.

For what it’s worth, the IDs returned by SetPreciseTimer are always 1 or greater, so 0 can indicate an invalid (never created) timer ID in your code.

When you call DeletePreciseTimer(somevariable), make sure to set somevariable = 0; as well.