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

[JASS] Does this BJ leak?

Status
Not open for further replies.
Level 11
Joined
Oct 11, 2012
Messages
711
Hi all. I know that most of the BJs are bad and I just want to know if the following BJ leaks region, or a more probable question:does local region leaks? Thanks:
JASS:
function TriggerRegisterEnterRectSimple takes trigger trig, rect r returns event
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
endfunction
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
yes, and no

The thing is, the region is not destroyed, but it cant be destroyed, because the trigger would not work properly anymore

This is because unlike TriggerRegisterTimerEvent creates its own internal timer object, but TriggerRegisterEnterRegion will not create copy of the region internally, so the region must live
 
Level 11
Joined
Oct 11, 2012
Messages
711
yes, and no

The thing is, the region is not destroyed, but it cant be destroyed, because the trigger would not work properly anymore

This is because unlike TriggerRegisterTimerEvent creates its own internal timer object, but TriggerRegisterEnterRegion will not create copy of the region internally, so the region must live

So you answer is, I can use this BJ without leaking issue? xD
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
If this region is a permanent member of your map, it has nothing what we would call a leak and the BJ is totally fine.
(Assuming the reference to that region doesn't matter, which I honestly don't know.)

But as edo already said, destroying that region will automatically lead to a handle leak, because you don't have access to local region rectRegion anymore.
Also the returned event will remain permantly.

Not using the BJ, will allow you to null that local region right away, which is important if you plan to destroy it at some point of the game.

We also have resources for optimal trigger usage such as Trigger, BooleanExpression, ... but they are very advanced and not available in the JASS section at the moment, furthermore I wouldn't recommend them to you, yet.

With GetTriggeringRegion() and GetTriggeringTrigger() you can gain access on the trigger and the region each time they are triggered.

Correct me if I'm wrong.
 
Level 11
Joined
Oct 11, 2012
Messages
711
If this region is a permanent member of your map, it has nothing what we would call a leak and the BJ is totally fine.
(Assuming the reference to that region doesn't matter, which I honestly don't know.)

But as edo already said, destroying that region will automatically lead to a handle leak, because you don't have access to local region rectRegion anymore.
Also the returned event will remain permantly.

Not using the BJ, will allow you to null that local region right away, which is important if you plan to destroy it at some point of the game.

We also have resources for optimal trigger usage such as Trigger, BooleanExpression, ... but they are very advanced and not available in the JASS section at the moment, furthermore I wouldn't recommend them to you, yet.

With GetTriggeringRegion() and GetTriggeringTrigger() you can gain access on the trigger and the region each time they are triggered.

Correct me if I'm wrong.
Actually I don't quite understand what a region is. I have not create any region in my triggers... :/
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
A region is an area in your map. Size and shape is defined by the rects you add to that region.
JASS:
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
You pass a rect into that BJ. That rect is now added to a region and the trigger fires whenever that region is entered by any unit.
 
Level 11
Joined
Oct 11, 2012
Messages
711
To put it another way: Regions are a union of rects. Regions need not be polygons (can be two areas on opposite sides of a map)
Thanks for the explanation, Cokemonkey11.
A region is an area in your map. Size and shape is defined by the rects you add to that region.
JASS:
    local region rectRegion = CreateRegion()
    call RegionAddRect(rectRegion, r)
    return TriggerRegisterEnterRegion(trig, rectRegion, null)
You pass a rect into that BJ. That rect is now added to a region and the trigger fires whenever that region is entered by any unit.

So if I need to keep using that rect later in the game, I can use that BJ safely, right?
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
You can use one static rect over your whole map, whenever you need it simply call SetRect(temp_rect..).
You can either make it a global inside the map header or what I did once make a struct with shared variables and then access it with for instance Variables.temp_rect.

Could look like this:
JASS:
library SharedVariables /*
*************************************************************************************
*
*   Collection of all variables used over multiple libraries and scopes of this map.
*
*   Variables can only be changed inside this library. temp_rect is an exception.
*
*************************************************************************************/

private module inits 
    private static method onInit takes nothing returns nothing
        local integer i = 0
        set temp_rect    = Rect(0.,0.,0.,0.) 
        set local_player = GetLocalPlayer()
        loop
            exitwhen i == bj_MAX_PLAYER_SLOTS
            set i = i + 1
            set player[i] = Player(i)
        endloop
    endmethod
endmodule

    struct Variables extends array
        readonly static integer playing_players 
        readonly static player local_player
        readonly static player array player [16]
        
        static rect temp_rect 
        
        static method operator players= takes integer value returns nothing
            set playing_players = value
        endmethod
        
        implement inits
        
    endstruct

endlibrary
 
Status
Not open for further replies.
Top