| 01-28-2007, 12:19 PM | #1 |
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. 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? JASS:call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, 10.00, "Something") Can I use localplayer like that? I mean, it works, but is it safe is the question. |
| 01-28-2007, 01:16 PM | #2 |
both shouldnt cause problems. |
| 01-28-2007, 01:21 PM | #3 |
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 |
Alright, then the problem must be elsewhere. Thanks guys. |
| 01-28-2007, 01:34 PM | #5 | |
Quote:
|
| 01-28-2007, 01:46 PM | #6 |
Oh, overlooked that sentense... no, that would probably desync indeed. |
| 01-28-2007, 02:08 PM | #7 |
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 | |
Quote:
|
| 01-29-2007, 12:03 PM | #9 |
yeah, welcome to 2006 |
| 02-05-2007, 10:55 PM | #10 |
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 |
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 JASS:local group g = udg_global_group if boolean == false then call SetUnitFacing( udg_Unit, 225.75 ) call DestroyGroup( g ) endif call DestroyGroup( g ) |
| 02-06-2007, 01:13 AM | #12 |
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 |
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 |
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 |
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. |
