View Issue Details

IDProjectCategoryView StatusLast Update
0006939Multi Theft Auto : San AndreasServerpublic2012-03-14 09:04
ReporterTjongAssigned Toccw 
PrioritynormalSeverityminorReproducibilitysometimes
Status resolvedResolutionfixed 
Product Version 
Target Version1.3.1Fixed in Version1.3.1 
Summary0006939: Expired timers can lead to wrong references
Description

Situation: You create a timer, which expires randomly between 1 and 10 seconds and you store the timer-reference in a global variable:
gTimer = setTimer(function () end, 1000 + math.random(9000), 1);

After 5 seconds a second routine is starting in which you're starting a second timer, which you don't store anywhere as this is not relevant.
Then you want to be sure, that the first timer is not running anymore, so you first check and then destroy:
if (gTimer and isTimer(gTimer)) then killTimer(gTimer); end

Now there are two cases:

  1. The first timer is expiring after > 5000 ms, then everything is certainly fine.
  2. The first timer already expired after 4000 ms or so, then the second setTimer call can return (by chance) the same timer-id as the first (already expired timer). So now your second timer started, BUT you're killing him straight afterwards, as gTimer is now pointing on the second timer and therefore "gTimer" as well as "isTimer(gTimer)" are returning positive values.
Steps To Reproduce

http://pastebin.com/wZkYWVLa

TagsNo tags attached.

Issue History

Date Modified Username Field Change