Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

JASS - Several questions

Discussion in 'World Editor Help Zone' started by Donach, Oct 30, 2017.

  1. Donach

    Donach

    Joined:
    Jan 12, 2011
    Messages:
    98
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Hello,
    I just wanted to ask several questions regarding JASS scripting.
    1. What about "call DestroyEffectBJ(AddSpecialEffectLocBJ(Params...))" with param being the actual Special Effect creation ? Will this do any bad, leaks etc?
    2. What about using "call TriggerSleepAction(X.Y)"? Is it safe to use in general? What about in loops? Any preference for this or for the "call PolledWait(X.Y)"?
    3. Just to ensure - local variables MUST be always removed and then nulled, except for real/int/string? Or String should be also nulled?

    Thanks for clarifying these queries!
     
  2. Jampion

    Jampion

    JASS Reviewer

    Joined:
    Mar 25, 2016
    Messages:
    1,287
    Resources:
    0
    Resources:
    0
    1. AddSpecialEffectLocBJ creates and returns a special effect, which uses memory. DestroyEffectBJ destroys the special effect (which is returned by AddSpecialEffectLocBJ) freeing the memory, so no memory leak occurs.

    its the same as
    Code (vJASS):
    local effect e = AddSpecialEffectLocBJ(...)
    call DestroyEffectBJ(e)

    just a bit shorter and without the need to use a variable

    if you want to code in JASS you should not be using BJ functions. Also avoid using locations, as (x,y)-coordinates are a lot better.

    2.TriggerSleepAction is the same as the GUI wait. It's inaccurate. I don't know much about TriggerSleepAction or PolledWait, because I prefer to use timers. They are better in most cases.

    3.you need to remove objects, before you null the variable. Once the variable is nulled or overwritten you can no longer access the object it previously pointed to and this object leaks.
    additionally local variables must also be nulled, except for the primitive types: int, real, boolean, string
     
  3. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,134
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Or function parameter declared local variables. The bug is only with local declared local handle variables.
     
  4. Donach

    Donach

    Joined:
    Jan 12, 2011
    Messages:
    98
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Thank you very much for the tips!
    Appreciated!



    Not quite sure I am following on this one. Function declares parameter in its "head" lets say, however there is no "local" thing there. But I guess I see the note about not needing to nullify these params.
    What bug is with the local handle?
     
  5. Dr Super Good

    Dr Super Good

    Spell Reviewer

    Joined:
    Jan 18, 2005
    Messages:
    26,134
    Resources:
    3
    Maps:
    1
    Spells:
    2
    Resources:
    3
    Code (vJASS):

    function LocalExample takes unit u1 returns nothing
        local unit u2
        set u1 = null // This is a function parameter declared local variable
        set u2 = null // This is a local declared local variable
    endfunction
     

    The local declared local handle variable reference counter leak on return bug.

    In order for a handle index to be recycled it must have no existing references to it. Every time a variable is assigned to a handle it increments the reference counter by 1. Every time a variable is assigned a different handle it decrements the counter by 1. Since local variables are also destroyed on function return it is meant to automatically decrement the counter by 1 before then as well. The bug is that this only happens for function parameter declared local variables. Local declared local variables do not decrement the handle counter when destroyed on function return, resulting in the handle index never being recycled, even long after the object it represented was destroyed.