HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Local Handle Vars Bug

02-20-2006, 03:31 PM#1
emjlr3
so I am aware of the Local Vars bug with setting locals to null that are used in it, my question is, which locals should I not set to null, now here is a basic ability trigger I just wrote:

Collapse JASS:
function Trig_Geo_Shield_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A004' 
endfunction

function Geo_Effects takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = GetHandleUnit(t,"u")
    local real r = GetHandleReal(t,"r")
    local real r2 = GetHandleReal(t,"r2")
    local real r3 = GetHandleReal(t,"r3")    
    local real x 
    local real y
    local integer i = 1
    local integer j = 0

    if GetUnitState(u, UNIT_STATE_LIFE) > 0 and GetUnitAbilityLevel(u, 'Binf') > 0 then
        loop
            exitwhen i>4            
            set x = GetUnitX(u) + r2 * Cos((r+j) * bj_DEGTORAD)
            set y = GetUnitY(u) + r2 * Sin((r+j) * bj_DEGTORAD)
            call DestroyEffect(AddSpecialEffect("Abilities\\Weapons\\AncientProtectorMissile\\AncientProtectorMissile.mdl",x,y))
            call DamageEnemiesArea(u,50, x, y, GetHeroStr(u,true)*.1, false, true, ATTACK_TYPE_SIEGE, DAMAGE_TYPE_DEMOLITION, WEAPON_TYPE_AXE_MEDIUM_CHOP) 
            set i = i + 1
            set j = j + 90
        endloop
    else
        call PauseTimer(t)
        call FlushHandleLocals(t)
        call DestroyTimer(t)
    endif
    call SetHandleReal(t,"r",r+GetRandomInt(8,12))
    if r2 >= 275 then
        call SetHandleReal(t,"r3",-(GetRandomInt(14,22))) 
    else
        if r2 <= 150 then
            call SetHandleReal(t,"r3",GetRandomInt(14,22))          
        endif
    endif 
    call SetHandleReal(t,"r2",r2+r3)   
    
    set t = null    
    set u = null
endfunction

function Trig_Geo_Shield_Actions takes nothing returns nothing
    local timer t = CreateTimer()
    
    call SetHandleHandle(t,"u",GetTriggerUnit())
    call SetHandleReal(t,"r",0)
    call SetHandleReal(t,"r2",275)    
    call SetHandleReal(t,"r3",18)
    call TimerStart(t, 0.09, true, function Geo_Effects)

    call TriggerSleepAction(25) 
    call PauseTimer(t)
    call FlushHandleLocals(t)   
    call DestroyTimer(t)

    set t = null
endfunction

//===========================================================================
function InitTrig_Geo_Shield takes nothing returns nothing
    set gg_trg_Geo_Shield = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Geo_Shield, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Geo_Shield, Condition( function Trig_Geo_Shield_Conditions ) )
    call TriggerAddAction( gg_trg_Geo_Shield, function Trig_Geo_Shield_Actions )
endfunction

which of those locals should I null and which should I not, i was under the impression that just locals that are used in Handles, so nulling

t both times, and both locations l and m would be fine

ty for the help
02-20-2006, 03:37 PM#2
Vexorian
you should only avoid to set locals to null if you find problems (unless you like memory leaks)

Random bugs that may appear or may not appear

and I think timer is the only kind of local that makes this
02-20-2006, 04:22 PM#3
emjlr3
lol what, I really didnt understand what you are saying ;)

set local to null only if I have problems?, so never ever set locals to null ever?

Quote:
Random bugs that may appear or may not appear

and I think timer is the only kind of local that makes this

and that just confused me
02-20-2006, 04:27 PM#4
Sardrixx
i do believe if you take that out of that sentence it makes perfect sense
02-20-2006, 05:03 PM#5
Vexorian
The bugs may happen when you do not set a timer to null. But only in very weird cases. Always set local variables of handle types to null unless you encounter problems.