• 🏆 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!

Help With Location Leak

Status
Not open for further replies.
Level 20
Joined
May 16, 2012
Messages
635
Hey guys, so, in my map i've created a spawn system that spawns 5 units of a given type and then 5 more of another type at 8 different locations (center of regions), which i assinged to a region vector. I loop through them checking which types of units should spawn (like in X Hero Siege fo eg) code below:

JASS:
private function Actions takes nothing returns nothing
    local integer i
    local location c
    set c = Location(GetRectCenterX(gg_rct_Castle), GetRectCenterY(gg_rct_Castle))
    if ( udg_Race_Turn == 0 ) then
        set i = 0
        loop
            exitwhen i > (udg_NumberOfPlayers_Integer - 1)
            call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'hfoo', Player(10), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
            call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
            call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'hrif', Player(11), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
            call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
            set i = i + 1
        endloop
        set udg_Race_Turn = 1
    else
        if ( udg_Race_Turn == 1 ) then
            set i = 0
            loop
                exitwhen i > ( udg_NumberOfPlayers_Integer - 1 )
                call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'ogru', Player(10), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
                call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
                call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'ohun', Player(11), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
                call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
                set i = i + 1
            endloop
            set udg_Race_Turn = 2
        else
            if ( udg_Race_Turn == 2 ) then
                set i = 0
                loop
                    exitwhen i > ( udg_NumberOfPlayers_Integer - 1 )
                    call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'ugho', Player(10), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
                    call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
                    call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'ucry', Player(11), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
                    call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
                    set i = i + 1
                endloop
                set udg_Race_Turn = 3
            else
                if ( udg_Race_Turn == 3 ) then
                    set i = 0
                    loop
                        exitwhen i > ( udg_NumberOfPlayers_Integer - 1 )
                        call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'esen', Player(10), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
                        call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
                        call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'earc', Player(11), Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i])), 0.00)
                        call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
                        set i = i + 1
                    endloop
                    set udg_Race_Turn = 0
                else
                endif
            endif
        endif
    endif
    call RemoveLocation(c)
    set c = null
endfunction

As you can see, i've created i little function called "CreateNUnitsLoc()" to aid me in this task, because i didn't want to use CreateNUnitsAtLoc(), i think its a bad BJ that calls 3 more functions to spawn the units, and since i cant use CreateUnitAtLoc() to create more than 1 unit, i decided to create my own, with 2 less functions calls than the BJ one. code below:

JASS:
function CreateNUnitsLoc takes integer count, integer unitid, player whichPlayer, location whichLoc, real face returns group
    local location l
    call GroupClear(bj_lastCreatedGroup)
    set l = whichLoc
    loop
        set count = count - 1
        exitwhen count < 0
            set bj_lastCreatedUnit = CreateUnitAtLoc(whichPlayer, unitid, l, face)
            call RemoveGuardPosition(bj_lastCreatedUnit)
            call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
    endloop
    call RemoveLocation(l)
    set l = null
    return bj_lastCreatedGroup
endfunction

Again, as you can see, i've created a local location to get rid of that nasty location leak and things were going well until i decided to go back in my Spawn code and do the same. i've create my locals to do so, but when i tried to do:

JASS:
    local location l
    local location c
    local integer i
    set c = Location(GetRectCenterX(gg_rct_Castle), GetRectCenterY(gg_rct_Castle))
    if ( udg_Race_Turn == 0 ) then
        set i = 0
        loop
            exitwhen i > (udg_NumberOfPlayers_Integer - 1)
            set l = Location(GetRectCenterX(udg_Spawn_Region_Vector[i]), GetRectCenterY(udg_Spawn_Region_Vector[i]))
            call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'hfoo', Player(10), l, 0.00)
            call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
            call CreateNUnitsLoc((5 * udg_Portal_Vector[i]), 'hrif', Player(11), l, 0.00)
            call GroupPointOrderLoc(bj_lastCreatedGroup, "attack", c)
            call RemoveLocation(l)
            set i = i + 1
        endloop
        set l = null
        set udg_Race_Turn = 1
    else

Only the first 5 units were being created. I realized that the leak was already being removed inside my "CreateNUnitsLoc()", finally, my question is: by removing the location leak at my created function, do i remove all the possible location leaks in my Spawn code?
 
Last edited:
Level 13
Joined
May 10, 2009
Messages
868
The idea is that the local variables will only reference that generated object (location). If you destroy it, they won't be able to reference it (null). So, to answer you question, yeah there won't be leaks from your code. However a leak is an object that has no more use and can't be referenced/destroyed anymore. In your case, that object is still needed.

I suggest that you either delete the RemoveLocation line from your custom function, or use coordinates (X, Y) instead.
 
Level 20
Joined
May 16, 2012
Messages
635
The idea is that the local variables will only reference that generated object (location). If you destroy it, they won't be able to reference it (null). So, to answer you question, yeah there won't be leaks from your code. However a leak is an object that has no more use and can't be referenced/destroyed anymore. In your case, that object is still needed.

I suggest that you either delete the RemoveLocation line from your custom function, or use coordinates (X, Y) instead.

ok, thx!
 
Status
Not open for further replies.
Top