HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Any way to safely destory a trigger?

06-23-2009, 06:22 AM#1
gekko
I know destroying a trigger during its run will cause bugs.

However, if the trigger to be destoryed has no waits or other stuff in it, can I safely destroy it in another trigger? Or should I turn it off and start an X second timer that destroys it later?

How can I avoid those bugs?
06-23-2009, 07:24 AM#2
Bobo_The_Kodo
To be safe, just have a stack of triggers which are deleted every x seconds. (AoM and DotA do this without bugs)
06-23-2009, 12:01 PM#3
Captain Griffen
We Don't Know (tm).

Quote:
However, if the trigger to be destoryed has no waits or other stuff in it, can I safely destroy it in another trigger? Or should I turn it off and start an X second timer that destroys it later?

Probably.
06-23-2009, 02:06 PM#4
fX_
i think triggers bug out in association with destroys only if they are destroyed while their stuff arent completed.

soooooo just wait a duration X > execution time for any trigger and destroy trigger.

you would likely not be using (Polled) waits so X would prob just be 0.0; if you do use them they would likely be for low durations only so X would be ----low.

Collapse JASS:
//uses TimerUtils

    globals
        private constant real X = 1.00 // greater than all trigger execution durations
    endglobals

    private keyword ResumeDestroyTriggerSafe

    function DestroyTriggerSafe takes trigger t returns nothing
        local timer TIM = NewTimer()

        call DisableTrigger(t) // so it doesnt run, anymore, as it is not meant to
        call SetTimerData(TIM, StoreTheTrigger(t)) //<-- i dont know: H2I() or its 1.23 equivalent or //w/e or some struct
        call TimerStart(TIM, X, false, function ResumeDestroyTriggerSafe)

        set TIM = null
    endfunction

    private function ResumeDestroyTriggerSafe takes nothing returns nothing
        local timer TIM = GetExpiredTimer()

        call DestroyTrigger(GetTheTrigger(GetTimerData(TIM)))

        call ReleaseTimer(TIM)
        set TIM = null
    endfunction

i dont know if this is the best method or if it is even good.
maybe you shouldnt be destroying triggers at all.
06-23-2009, 03:35 PM#5
gekko
Quote:
Originally Posted by fX_
i dont know if this is the best method or if it is even good.
maybe you shouldnt be destroying triggers at all.

I know ;) But sometimes there is just no other way to get rid of registered events. I guess I will use the timer solution. Or maybe the stack to save timer executions (less computation time ;) )
06-23-2009, 03:50 PM#6
emjlr3
wait 60 seconds and kill it

another option is not to use triggersleepaction, ever, and you don't need to worry (shouldn't)
06-23-2009, 04:50 PM#7
akolyt0r
To sum common knowledge, and the content of this thread until now, you should try to do following things to be sure your dynamic triggers wont cause any bugs, most probably:
- dont use any triggersleepaction (esp in the dynamic triggers, and triggers related to them)
- use triggerconditions instead of triggeractions (automatically prevent the usage of triggersleepaction, and are faster)
- wait some time (>60secs minimum) before you destroy them
06-23-2009, 05:04 PM#8
Tyrande_ma3x
> wait 60 seconds and kill it
> - wait some time (>60secs minimum) before you destroy them
Why wait so much? War3 has some delayed handle recycling or what?
06-23-2009, 05:05 PM#9
Captain Griffen
Do all of them and you still won't be completely sure.

Quote:
- use triggerconditions instead of triggeractions (automatically prevent the usage of triggersleepaction, and are faster)

You can bug triggers with just conditions fired by them.
06-23-2009, 06:09 PM#10
Anitarf
Quote:
Originally Posted by gekko
I know ;) But sometimes there is just no other way to get rid of registered events. I guess I will use the timer solution. Or maybe the stack to save timer executions (less computation time ;) )
Do what I do and make it optional. If the users ever gets weird bugs, they can then turn off the trigger destruction to test if that's the cause.
06-24-2009, 08:17 PM#11
gekko
Quote:
Originally Posted by Captain Griffen
You can bug triggers with just conditions fired by them.
How do you mean that?
06-24-2009, 08:34 PM#12
grim001
I still haven't seen any proof that DestroyTrigger related bugs actually happen if you code competently.
06-25-2009, 07:15 AM#13
Captain Griffen
Quote:
Originally Posted by gekko
How do you mean that?

I mean a trigger with just conditions fired by it can still bug when destroyed.