HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Timer Stack Safety

01-28-2007, 12:19 PM#1
Rising_Dusk
Okay, well I've been using a timer stack series of functions for AotZ for awhile now, but ever since I started using them the map seems to randomly desync players.
I'm not 100% sure it is the stack's fault, since I did add other things that version, but I want to make sure I'm using it properly and safely.

Collapse JASS:
//***************************************************************************************************************
//*Gets a new timer from the array to use for whatever it's needed for.
//*
function NewTimer takes nothing returns timer
    if (udg_T_N == 0) then
        return CreateTimer()
    endif
    set udg_T_N = udg_T_N - 1
    return udg_T_Timers[udg_T_N]
endfunction

//***************************************************************************************************************
//*Releases a timer that has finished being used.
//*
function ReleaseTimer takes timer t returns nothing
    call FlushLocals(t)
    call PauseTimer(t)
    if (udg_T_N == 8191) then
        call BJDebugMsg("Warning: Timer stack is full, destroying timer!")
        //*************************************************************************
        //**Stack is full, the map already has more problems than bugs
        call DestroyTimer(t)
    else
        set udg_T_Timers[udg_T_N] = t
        set udg_T_N = udg_T_N + 1
    endif    
endfunction

Also, I attach lots of variables to these timers via cache, which is why there is a FlushLocals() call on the timer in the ReleaseTimer() call.
That wouldn't be a problem, would it?

EDIT:
Let me also tack in here another question --
Is this safe?
Collapse JASS:
call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10.00, "Something")
I also use it in TriggerRegisterPlayerEvent() calls.
Can I use localplayer like that? I mean, it works, but is it safe is the question.
01-28-2007, 01:16 PM#2
iNfraNe
both shouldnt cause problems.
01-28-2007, 01:21 PM#3
Vexorian
A timer stack seems as unlikely to cause desyncs as ever. Anyways, when using it beware of double-free it can make things really bad (to add the same timer twice to the stack)
01-28-2007, 01:23 PM#4
Rising_Dusk
Alright, then the problem must be elsewhere.
Thanks guys.
01-28-2007, 01:34 PM#5
shadow1500
Quote:
I also use it in TriggerRegisterPlayerEvent() calls.
Last time I checked you can't make local events.
01-28-2007, 01:46 PM#6
iNfraNe
Oh, overlooked that sentense... no, that would probably desync indeed.
01-28-2007, 02:08 PM#7
Rising_Dusk
Really now?
That's interesting indeed...

I think I do that in like 20 places.
Let me go fix that...
01-29-2007, 10:22 AM#8
Toadcop
Quote:
A timer stack seems as unlikely to cause desyncs as ever. Anyways, when using it beware of double-free it can make things really bad (to add the same timer twice to the stack)
what why my precache method is much saver because if have check for double recycles...
01-29-2007, 12:03 PM#9
Vexorian
yeah, welcome to 2006
02-05-2007, 10:55 PM#10
Rising_Dusk
I'm bumping this because I need clarification on something Vex mentioned here.
Could anyone elaborate upon the concept of 'Double-free' and how it might occur?
02-05-2007, 11:38 PM#11
Pyrogasm
As far as I know, a "Double-free of XX" occurs when you clear/null/remove something that has already been cleared/null'd/removed. E.G. if you do this
Collapse JASS:
local group g = udg_global_group
if boolean == false then
    call SetUnitFacing( udg_Unit, 225.75 )
    call DestroyGroup( g )
endif
call DestroyGroup( g )
But then again, I ain't no JASS guru, so I could be wrong.
02-06-2007, 01:13 AM#12
Naakaloh
I think what he may have meant is if you use a function to "free-up" timers and you accidentally call it twice in which case it's added to the stack of free timers twice.
02-06-2007, 02:15 AM#13
Pyrogasm
So I appear to not have answered Dusk's question, but is what I posted correct? (For my own knowlege)
02-06-2007, 10:37 AM#14
Captain Griffen
Yes, it could result in one timer being used twice at the same time. Wouldn't cause a desync unless used for a local player, just screw stuff up.
02-06-2007, 11:52 AM#15
Rising_Dusk
So but are there any other ways to induce "double free" without freeing a timer twice?
I'm just checking through, and I don't *think* I've double freed anything.
But ya' never know.

And thanks guys for the answers.