1. Head to the 33rd Modeling Contest Poll and drink to your heart's desire.
    Dismiss Notice
  2. Choose your means of doom in the 17th Mini Mapping Contest Poll.
    Dismiss Notice
  3. A slave to two rhythms, the 22nd Terraining Contest is here.
    Dismiss Notice
  4. The heavens smile on the old faithful. The 16th Techtree Contest has begun.
    Dismiss Notice
  5. The die is cast - the 6th Melee Mapping Contest results have been announced. Onward to the Hive Cup!
    Dismiss Notice
  6. The glory of the 20th Icon Contest is yours for the taking!
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] What to do with triggers?

Discussion in 'Triggers & Scripts' started by Marcelo Hossomi, Feb 18, 2009.

  1. Eccho

    Eccho

    Joined:
    Nov 29, 2006
    Messages:
    2,297
    Resources:
    2
    Spells:
    2
    Resources:
    2
    Why would you destroy a trigger before sleeping it in the first place I wonder? And it seems, regarding my testing that it never occured with only one triggersleepaction (with >=2 it did though).
    Hm also, storing the group in a variable instantly after each other and then compare them seems to make the risk smaller.

    But yeah, it is buggy that's for sure.
     
  2. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    TriggerSleepAction is buggy
    this has nothing to do with DestroyTrigger
     
  3. Eccho

    Eccho

    Joined:
    Nov 29, 2006
    Messages:
    2,297
    Resources:
    2
    Spells:
    2
    Resources:
    2
    I never said so either.
     
  4. Deaod

    Deaod

    Joined:
    Nov 18, 2007
    Messages:
    805
    Resources:
    12
    Maps:
    1
    Spells:
    11
    Resources:
    12
    May i ask you for evidence? Abusing TSA is not a bug. Its called TriggerSleepAction for a reason.
     
  5. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    Well
    I have some

    1- If you use TSA in functions executed via ForGroup, it causes thread crash
    2- If you use TSA in functions executed via a timer, it causes thread crash

    and Its not accurate
    shortest pause with TSA is granted with TSA(-1) <I guess it was 0.15 secs
    TSA(-2) => 0.25 and TSA(0) => 0.2 as I remember
    TSA(1) is like random wait between 0.5 and 1.5 secs

    and in the bug proof you sent if you remove TSAs its fine (its fine if you even remove one of them)
     
  6. Deaod

    Deaod

    Joined:
    Nov 18, 2007
    Messages:
    805
    Resources:
    12
    Maps:
    1
    Spells:
    11
    Resources:
    12
    both cases are incorrect usage of TSA, and no bug of TSA. As i said, its called TriggerSleepAction, so dont expect it to work in anything else than TriggerActions.

    Edit: Guess what: if you remove DestroyTrigger(), theres no bug.
     
  7. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    Its unaccurate in trigger actions too
    will you stop insisting on that please ?
    you seem to have blinded yourself
     
  8. Marcelo Hossomi

    Marcelo Hossomi

    Joined:
    Dec 31, 2005
    Messages:
    710
    Resources:
    3
    Models:
    2
    Spells:
    1
    Resources:
    3
    (let me take two steps away from the discussion o.o')

    If destroying groups bugs too (just ignore it Need_O2 >.>), enum units in range would require creating/destroying groups. So I guess I haven't reached a solution xD

    Anyway, I haven't had any problems with DestroyTrigger() and no other handle destroying functions.
    And I use them in almost all my systems.
    In my last work there was about 5 missiles per second, each one with a dinamic trigger (I need them to detect units in range, I think it's better than enum units) and destroying it in the end.
    I played it for 2 hours, no problems...
     
  9. Soga-

    Soga-

    Joined:
    Jul 20, 2008
    Messages:
    374
    Resources:
    0
    Resources:
    0
    There's no bug with destroying groups.

    As for destroying triggers, I have yet to confirm for myself that it bugs. I've worked with a damage detection system making heavy use of DestroyTrigger(), and had no problems with the game.

    But then again, I don't think I really got that far in that map as to ensure one object was separate from another.

    So I'm really interested in this thread.

    EDIT: Oh, I see now. DestroyTrigger() only bugs if you destroy a trigger that's still running, correct? So if it's not running, it's safe to destroy?
     
  10. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    Well... umm... I recycle a single group everytime for things like AoE spells (ForTheAll)
    Well and Unit Recycling is a better way for sure, not because of DestroyTrigger bugs but creating destroying trigger each time isnt so healthy ofc

    Unit Recycling works like:
    you have a footman, when it dies its food cost is disabled it gets hidden and moved to some place named Haven (lol)
    When you create another footman, the footman gets repleaced with footman in haven (buffs removed and health filled ofc)
    Ofc its a bit more complicated xD but it works like this

    Anyway just dont create-destroy much things
     
  11. Deaod

    Deaod

    Joined:
    Nov 18, 2007
    Messages:
    805
    Resources:
    12
    Maps:
    1
    Spells:
    11
    Resources:
    12
    You not having run into any bugs doesnt mean there are none.

    No exactly a bug, but once you use certain functions (i think it was ForGroup()) on groups they leak, even when destroyed.

    Thats the most common explanation.

    Its accurate enough for GUI, so why bother. If you want more accuracy, go for timers. And i dont consider inaccuracy a "bug". Its more due to the way this function works internally.
     
  12. Akolyt0r

    Akolyt0r

    Joined:
    Dec 20, 2008
    Messages:
    53
    Resources:
    3
    Icons:
    3
    Resources:
    3
    DestroyGroup will cause some leaks if you used some special natives for that group before as far i know.
    So Recycling them is good...there is a good script named GroupUtils available over at war3campaigns which achieves that and it also got a GroupRefresh function to get rid of ShadowUnits...

    Normally you dont need that however, because you can one global group for most stuff...when doing this you shouldnt use ForGroup calls however, do your Actions in the Filterfunction instead (and NEVER use "null" as filter, because it leaks).

    And if you really insist on using DestroyTrigger on dynamic triggers, you should destroy them after some time, after the trigger has been run ...(maybe 5-30 seconds, but PLEASE dont use TriggerSleepAction for that delay ...use timers ..4 real).

    There are aswell problems regarding destroying timers ..i dont know excactly what it was again ...but i really dont care because recylcing them is faster anyway ....and of course TimerUtils functions (SetTimerData / GetTimerData) are pure awesomness..
     
  13. Marcelo Hossomi

    Marcelo Hossomi

    Joined:
    Dec 31, 2005
    Messages:
    710
    Resources:
    3
    Models:
    2
    Spells:
    1
    Resources:
    3
    I think that's just what I need!
    I haven't thought about that :p

    However I'll use TimerUtils and enum for whatever I need, recycling groups as they suggested.

    Thanks you all :p
    And please don't kill each other x.o
     
  14. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    meh my anger has ran out so I'll stick with light side
    Deaod and Akolyt0r I love you both
     
  15. Soga-

    Soga-

    Joined:
    Jul 20, 2008
    Messages:
    374
    Resources:
    0
    Resources:
    0
    Sorry to necropost, but I ran a few tests. I don't think DestroyTrigger() really bugs. Why? Because when I tried the DestroyTrigger bug - it would bug when I typed -bug (and even up to like 100 times).

    However, when I ran another trigger AFTER running the bug trigger 100 times:
    Code (vJASS):
    function Trig_test_Actions takes nothing returns nothing
        local integer i=0
        loop
            exitwhen i>=20
            if CreateGroup() == CreateGroup() then
                call BJDebugMsg("|cFFFF0000Bug Caught|r")
            else
                call BJDebugMsg("|cFF00FF00No Bug Caught|r")
            endif
            set i=i+1
        endloop
    endfunction

    //===========================================================================
    function InitTrig_test takes nothing returns nothing
        set gg_trg_test = CreateTrigger(  )
        call TriggerRegisterPlayerChatEvent( gg_trg_test, Player(0), "-compare", true )
        call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
    endfunction


    when I type -compare, there is no bug caught. In fact, I also just modified it so that the bug trigger does not create any groups, and I made -compare only do one check. It did not catch any bugs either.

    So I think Need_O2 was right, DestroyTrigger() does not bug at the fundamental level... it's just how you use it. As he said before, TSA was also at fault. So I think there's more to this bug than just DestroyTrigger() and just TSA.

    EDIT: Just ran further experiments. Calling a function that destroys the calling trigger does not cause any bugs. Neither does running a concurrent trigger (runs while the main bugging trigger is sleeping) to destroy the first trigger bugged it.

    In short, DestroyTrigger() seems to be safe as long as you avoid using waits in the trigger that's being destroyed.
     
    Last edited: Mar 2, 2009
  16. Eccho

    Eccho

    Joined:
    Nov 29, 2006
    Messages:
    2,297
    Resources:
    2
    Spells:
    2
    Resources:
    2
    It seems that we may be able to avoid the destroytrigger bug by using triggerconditions instead of triggeractions, since these are not threaded. However, it's not certain yet.

    And Soga, that wasn't really a necropost.
     
  17. Deaod

    Deaod

    Joined:
    Nov 18, 2007
    Messages:
    805
    Resources:
    12
    Maps:
    1
    Spells:
    11
    Resources:
    12
    That doesnt change the fact that using dynamic triggers indicates a flawed conception of your code.
     
  18. Eccho

    Eccho

    Joined:
    Nov 29, 2006
    Messages:
    2,297
    Resources:
    2
    Spells:
    2
    Resources:
    2
    I know, Deaod, I know. I just happend to see the thread at wc3c...
     
  19. Need_O2

    Need_O2

    Joined:
    Aug 24, 2007
    Messages:
    2,880
    Resources:
    0
    Resources:
    0
    Indexing is the best
    end of subject
     
  20. Soga-

    Soga-

    Joined:
    Jul 20, 2008
    Messages:
    374
    Resources:
    0
    Resources:
    0
    Dynamic triggers are required for damage detection. I just think the danger of using dynamic triggers is way overblown.