| 04-08-2007, 09:26 PM | #1 |
I've heard that both nulling timers and triggers can be bad, and may result in huge errors (H2I not working?). My question is why, and how? I know this question has been answered before, but all threads I've searched don't really have a definite answer. For instance: JASS:function Test1 takes nothing returns nothing local timer t = CreateTimer() call DoStuffWithTimer(t) call DestoryTimer(t) set t = null endfunction shouldn't yield problems, but people say it does. Is it when you get the integer of a timer, store it, destroy it, and then try and do something with that timer-integer? Can someone please explain exactly what I should not do, and then maybe a method around it. Thanks. |
| 04-08-2007, 09:45 PM | #2 |
Destroyed timers can expire. This can create massive problems, as the handle index gets totally confused. Also doing anything with a destroyed object is a bad idea. So pause timers before destroying them, and you ought to be fine. Non-repeating timers don't have this issue that I am aware of. I've never had a problem with nulling timers, but then again for most of mine I very rarely use auto-repeating timers that I destroy (due to TimerAttach not working with them). |
| 04-08-2007, 10:08 PM | #3 |
Okay, makes sense. I usually pause timers anyways, so that the timer doesn't happen twice for some reason, giving an added bonus. What about triggers? Someone once told me that I shouldn't dynamically create and destroy them, but I'm still not sure as to why. |
| 04-08-2007, 10:19 PM | #4 |
I avoid dynamically created triggers. There appears to be some problem where destroying triggers can cause the handle stack to get corrupted, resulting in even variables getting messed up, I think, and totally messing up any handle index based systems. However, I think it was found that setting the trigger and its parts to variables before destroying them (rather than straight I2Trigger) radically reduced this, probably even eliminating it. Oh, and I just remembered - recycling timers is much safer and more efficient than destroying them. Very easy as well if you use a preprocessor. See Vex's safe timer stuff for more info. EDIT: Changed to say what I meant; timers, not triggers. |
| 04-08-2007, 10:23 PM | #5 |
Recycling triggers is impossible. Recycling timers is only partially effective. It seems that it is better to avoid "dynamic triggers" and converting integer to any handle. |
| 04-08-2007, 10:42 PM | #6 | |
Do you think the trigger mess-up revolves around trying to null a destroyed trigger? I do use preprocessors, but I don't use structs and I try and stay away from Game Cache now. I use my own global variables and what not. Quote:
I was working on a combat system that detected when a unit took damage, and I used a dynamic trigger, yet there was only 1 trigger at a time, stored to a variable. Would that be safe (no integer-handle bug or anything)? In the end, the whole system should be scripted without the trigger creation, but it was just for ease of coding at the time. |
| 04-08-2007, 11:38 PM | #7 |
I don't think you can do it without the trigger creation, not correctly or fast anyways. In theory, simply allowing casts from integer to handles and to destroy triggers before all the threads created by the trigger end should be enough, but it is not a warrant. |
| 04-08-2007, 11:55 PM | #8 |
If you want a system that can be used similarly to gamecache without I2H or the possibility of any kind of glitches you could use my DataSystem which is really just an extended version of CSData. |
| 05-19-2007, 10:16 PM | #9 |
is nulling local variables bad? |
| 05-19-2007, 10:22 PM | #10 |
If they're not destroyed yet, yes. |
| 05-19-2007, 10:26 PM | #11 |
ugh, I meant "triggers" where i wrote "variables". Isn't destroying Triggers bad? So, would that mean you shouldnt even null the local trigger? |
| 05-20-2007, 03:10 AM | #12 |
Not really. Destroy the trigger messes with the handle indexing, whereas nulling a reference to it just make it sit there doing nothing, but keeping the indexing and crap safe. |
| 05-20-2007, 01:39 PM | #13 |
My theory is that dynamic triggers + handle vars = 100% corruption. In my map, there are 9999 dynamic triggers. They did seem to have caused some problems. But after having switched over to globals and vjass, the bugs seemed to be nullified. |
