• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

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: 58
Status
Not open for further replies.
Top