• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Leaking when enum fails

Status
Not open for further replies.
Level 21
Joined
Mar 27, 2012
Messages
3,232
Try using the ability named Absorb Souls. The problem here is that when there are no souls around the handle count keeps rising.
According to task manager the warcraft3 process gains about 20k of memory over an hour. This might be small alone, but I have other similar triggers.
Thus, I can't afford this kind of leaks.
I have implemented a handle counter and disabled all irrelevant triggers, so you can test this out.
EDIT: Forgot to attach map
JASS:
function IsUnitSoul takes nothing returns boolean
if GetUnitTypeId(GetFilterUnit()) == 'n013' and GetUnitState(GetFilterUnit(),UNIT_STATE_LIFE) > 0.4 then
    return true
endif
return false
endfunction

function AbsorbSouls takes nothing returns nothing
    local unit caster = GetEnumUnit()
    local group g = CreateGroup()
    local unit u
    local real speed = 3
    local location casterloc = GetUnitLoc(caster)
    local location l
    local location m
    if GetUnitCurrentOrder(caster) == OrderId("unrobogoblin") then
        call GroupEnumUnitsInRange(g,GetUnitX(caster),GetUnitY(caster),768,function IsUnitSoul)
        if IsUnitGroupEmptyBJ(g) == false then
            set u = FirstOfGroup(g)
            loop
                exitwhen u == null
                set l = GetUnitLoc(u)
                set m = PolarProjectionBJ(l,speed,AngleBetweenPoints(l,casterloc))
                if DistanceBetweenPoints(m,casterloc) > speed then
                    call SetUnitX(u,GetLocationX(m))
                    call SetUnitY(u,GetLocationY(m))
                else
                    call SetUnitState(caster,UNIT_STATE_LIFE,GetUnitState(caster,UNIT_STATE_LIFE)+GetUnitState(u,UNIT_STATE_LIFE))
                    call SetUnitState(caster,UNIT_STATE_MANA,GetUnitState(caster,UNIT_STATE_MANA)+GetUnitState(u,UNIT_STATE_MANA))
                    call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Undead\\ReplenishMana\\SpiritTouchTarget.mdl",GetUnitX(caster),GetUnitY(caster)))
                    if GetUnitAbilityLevel(caster,'A02B') < 100 then
                        call IncUnitAbilityLevel(caster,'A02B')
                    endif
                    call KillUnit(u)
                endif
                call RemoveLocation(l)
                set l = null
                call RemoveLocation(m)
                set m = null
                call GroupRemoveUnit(g,u)
                set u = null
                set u = FirstOfGroup(g)
            endloop
        endif
    else
        //call IssueImmediateOrder(caster,"stop")
        call GroupRemoveUnit(SoulAbsorbers,caster)
    endif
    call RemoveLocation(casterloc)
    set casterloc = null
    call DestroyGroup(g)
    set g = null
    set caster = null
endfunction

function Trig_AbsorbSoulsLoop_Actions takes nothing returns nothing
    if IsUnitGroupDeadBJ(SoulAbsorbers) == false then
        call ForGroup(SoulAbsorbers,function AbsorbSouls)
    else
        call DisableTrigger(gg_trg_AbsorbSoulsLoop)
    endif
endfunction

//===========================================================================
function InitTrig_AbsorbSoulsLoop takes nothing returns nothing
    set gg_trg_AbsorbSoulsLoop = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_AbsorbSoulsLoop, 0.03 )
    call TriggerAddAction( gg_trg_AbsorbSoulsLoop, function Trig_AbsorbSoulsLoop_Actions )
endfunction
 

Attachments

  • Essence of Magic v0.02a.w3x
    1.6 MB · Views: 59
Status
Not open for further replies.
Top