HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

TimerGetRemaining() Bug

07-29-2007, 04:02 AM#1
Pyrogasm
Well, I appear to have discovered a bug with TimerGetRemaining() and TimerGetElapsed(). It seems as though if you start a timer and then (before the timer has expired) do the following:
  • Pause the timer
  • Store the Time Remaining to a variable (or display it with a debug)
  • Re-start the timer with TimerStart() with any function as the callback
And then get the Elapsed time in the new callback function after the timer expires, it will be exactly the same as before the timer was restarted.

If, however, you do not pause the timer before restarting, all is well and the second display is 0.00 seconds remaining.

TimerGetElapsed() also bugs out, but I can't seem to figure out how it comes up with the number it does. I keep getting TimeoutOfTheTimer * -1.00 - 0.1 or something like that.

Here's what I used to test:
Collapse JASS:
function Callback_Test takes nothing returns nothing
    call PauseTimer(udg_TestTimer)
    call BJDebugMsg("Second Remaining: "+R2S(TimerGetRemaining(udg_TestTimer)))
    call DestroyTimer(udg_TestTimer)
endfunction

function Trig_Test_Actions takes nothing returns nothing
    call BJDebugMsg("Started")
    if udg_TestTimer == null then
        set udg_TestTimer = CreateTimer()
    endif
    call TimerStart(udg_TestTimer, 10.00, false, function Callback_Test)
    call PolledWait(5.00)

    call PauseTimer(udg_TestTimer)
    call BJDebugMsg("First Remaining: "+R2S(TimerGetRemaining(udg_TestTimer)))
    call TimerStart(udg_TestTimer, 2.00, false, function Callback_Test)
endfunction

function Callback_Test2 takes nothing returns nothing
    call PauseTimer(udg_TestTimer)
    call BJDebugMsg("Second Elapsed: "+R2S(TimerGetElapsed(udg_TestTimer)))
    call DestroyTimer(udg_TestTimer)
endfunction

function Trig_Test_Actions2 takes nothing returns nothing
    call BJDebugMsg("Started Again")
    if udg_TestTimer == null then
        set udg_TestTimer = CreateTimer()
    endif
    call TimerStart(udg_TestTimer, 10.00, false, function Callback_Test2)
    call PolledWait(5.00)

    call PauseTimer(udg_TestTimer)
    call BJDebugMsg("First Elapsed: "+R2S(TimerGetElapsed(udg_TestTimer)))
    call TimerStart(udg_TestTimer, 2.00, false, function Callback_Test2)
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent(gg_trg_Test, Player(5), "Start", true)
    call TriggerAddAction( gg_trg_Test, function Trig_Test_Actions )
endfunction
07-29-2007, 06:32 AM#2
DioD
this effect was used in this system.

http://www.wc3campaigns.net/showthread.php?t=84804

via timer's bug stuff was saved inside timers.
07-29-2007, 12:15 PM#3
Toadcop
O_O
Collapse JASS:
globals
  timer ttt=CreateTimer()
  timer t2=CreateTimer()
endglobals

function blabla takes nothing returns nothing
endfunction

function xxx takes nothing returns nothing
    call TimerStart(ttt,1,false,null)
    call PauseTimer(ttt)
    call TimerStart(ttt,5,false,function blabla)
    call echo("Remain "+R2S(TimerGetRemaining(ttt))) // in my case 5 sec and so should it be.
endfunction

function test takes nothing returns nothing
    call TimerStart(ttt,10,false,null)
    call TimerStart(t2,1,false,function xxx)
endfunction

well what's the problem here in my code ? i can't reproduce it =\ and i got a map there i am have A LOT pausing and starting and i have not mentioned any issue (for so long). dunno maybe platform related or something...

plz write here normal code example not yours with some PolledWait() and etc... the pure construction which would acts like u descibed.


Ahhh ! after the timer expires y can get it... well stupid bug ^^
07-29-2007, 06:27 PM#4
Pyrogasm
Collapse JASS:
globals
    timer TheTimer
    timer HelperTimer
endglobals

function CallbackDisplay takes nothing returns nothing
    call BJDebugMsg("Remaining: "+R2S(TimerGetRemaining(TheTimer)))

    call PauseTimer(TheTimer)
    call DestroyTimer(TheTimer)
    set TheTimer = CreateTimer()
endfunction

function Interrupt takes nothing returns nothing
    call PauseTimer(TheTimer)
    call BJDebugMsg("Remaining: "+R2S(TimerGetRemaining(TheTimer)))
    call TimerStart(TheTimer, 1.00, false, function CallbackDisplay)

    call PauseTimer(HelperTimer)
    call DestroyTimer(HelperTimer)
    set HelperTimer = CreateTimer()
endfunction

function Start takes nothing returns nothing
    call TimerStart(TheTimer, 10.00, false, null)
    call TimerStart(HelperTImer, 3.00, false, function Interrupt)
endfunction
07-30-2007, 12:52 AM#5
Captain Griffen
*yawn*

Old news. Used in my TimerAttach function.

Solution: Don't pause timers and then restart them without knowing what you are doing.
07-30-2007, 02:47 AM#6
Pyrogasm
Really?

Damn.