• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Checking leaks

Status
Not open for further replies.
Level 9
Joined
Oct 17, 2007
Messages
547
If i trigger add a unit at a random point in a region will that leak? If it does how do i fix it?
If i want to get rid of leaks manually for an array how can i do it?
How do i make i so the minimap starts out unexplored all black?
 
Last edited:
Level 11
Joined
Feb 22, 2006
Messages
752
Adding a unit at a random point in a region using GUI triggers will leak the location and the region (well, it depends on what you define the region to be). There are two ways to fix it:

  1. Use JASS. This is the most efficient way, as with JASS you can make sure you never (well, almost never) leak anything.

    JASS:
    function CreateUnitAtRandomPointInRegion takes nothing returns nothing
        local rect r = bj_mapInitialPlayableArea
        local real minx = GetRectMinX( r )
        local real miny = GetRectMinY( r )
        local real maxx = GetRectMaxX( r )
        local real maxy = GetRectMaxY( r )
        call CreateUnit( Player(0), 'hfoo', GetRandomReal( minx, maxx), GetRandomReal( miny, maxy), GetRandomReal( 1, 360 ) )
        set r = null
    endfunction

    In this particular example a footman belonging to Player 1 (Red) would be created at a random point within the rect defined to be the entire playable map area. Of course, you can set the Rect to be anything you want by calling the function Rect() instead of just defining r as bj_mapInitialPlayableArea. (Actually if you were to do that you might as well forgo the rect entirely and just directly define the min and max x,y coordinates - since Rect() requires you to input those values anyways)

  2. Use the "Custom Script" option in the GUI Actions list and create local variables and store your random location and your rect in those locals, for example:

    JASS:
    local rect r = bj_mapInitialPlayableArea
    local location loc = GetRandomLocInRect( r )

    Then when you are done with those variables, destroy/remove them and nullify them.

    JASS:
    call RemoveLocation( loc )
    set r = null
    set loc = null

    Here we didn't destroy the rect r because it holds a bj global, the entire playable map area, which does not need to be destroyed. However, if you define the rect to be something else, then you would need to destroy the rect using RemoveRect(). Note that r still needs to be nullified, though, because the variable r itself is separate from bj_mapInitialPlayableArea and would cause memory leaks if not nullified.




To get rid of leaks manually for an array, the best way is again JASS, so say you had a location array and wanted to get rid of all leaks.

JASS:
function GetRidOfLeaks takes nothing returns nothing
    local location array loc
    local integer counter = 0
    //...some code that defines each of the array indexes for loc
    loop
       exitwhen ( loc[counter] == null )
       call RemoveLocation( loc[counter] )
       set loc[counter] = null
       set counter = counter + 1
    endloop
endfunction

Of course, this assumes that you logically fill up the array always using the smallest open index: loc[0], then loc[1], then loc[2], etc. (but why wouldn't you?)


For the minimap, there's an option in Scenario -> Map Options (or something like that) where you can set the fog of war to begin as black mask (instead of terrain explored)
 
Level 11
Joined
Feb 22, 2006
Messages
752
Well, regardless of whether he understands it or not, these are the only ways to get rid of those leaks. There's no easy global you can set to true like bj_wantDestroyGroup to destroy GUI-created rects. Nor do the BJ functions set the created rects to a handy global like bj_lastCreated... (in fact rects and regions are one of the FEW handles that don't have a bj global like that made for them.)
 
Level 9
Joined
Oct 17, 2007
Messages
547
Well i'll try to make it into 1 point variable instead of an array and destroy after since thats easier and doable in GUI. Cus.. JASS knows me.. but i dont know it :D not yet anyways. Thanks a lot anyways aznrice appreciate your help.
 
Status
Not open for further replies.
Top