Help with controlling leaks, did I do this right?

afisakov

You can change this now in User CP.
Reaction score
37
I am trying to fix some leaks in a map that spawns units like this
Code:
call CreateNUnitsAtLoc($F,'n006',Player($C),GetRectCenter(JV),bj_UNIT_FACING)
call GroupPointOrderByIdLoc(GetLastCreatedGroup(),$D0016,GetRectCenter(mV))
my attempt at a fix looks like
Code:
set spa=15
set hx=GetRectCenter(JV)
set gx=GetRectCenter(mV)
set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = spa
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        call CreateNUnitsAtLoc( 1, 'n006', Player(0), udg_hx, bj_UNIT_FACING )
        call IssuePointOrderLocBJ( GetLastCreatedUnit(), "attack",gx)
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
call RemoveLocation (hx)
call RemoveLocation (gx)
so my question is 2 parts
1) did I fix all the leaks, hopefully make something that does not leak
2) is it true to the original function? I ask because I am not entirely sure what
Code:
call GroupPointOrderByIdLoc(GetLastCreatedGroup(),$D0016,GetRectCenter(mV))
does and am assuming it is a type of attack-move, if not can someone please tell me how to fix my code to do the right thing without introducing a leak?

Thanks in advance for the help
 

WaterKnight

Member
Reaction score
7
hx and gx should be nulled after you have removed their objects in case those are local variables.

CreateNUnitsAtLoc can be replaced by

JASS:
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit


You actually do not even need a location and there is GetRectCenterX/Y. Same goes for the order function with

JASS:
native IssuePointOrder takes unit whichUnit, string order, real x, real y returns boolean


respectively

JASS:
native IssuePointOrderById takes unit whichUnit, integer order, real x, real y returns boolean


second takes a numeric order id as was already required by the grouporder function. Grouporders are not exactly the same, they order all units together in formation. Also be careful when using global variables as iterators like bj_forLoopAIndex here because the order action for example may trigger order events and therefore run other parts of your code that make use of bj_forLoopAIndex themselves and therefore overwrite it before your loop has been completed.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top