• 🏆 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] Memory Leak Questions

Status
Not open for further replies.
Level 6
Joined
Jun 30, 2006
Messages
230
If I understand the memory leaks correctly, the following code would not leak:
JASS:
function Trig_SG takes nothing returns nothing
    call SetPlayerStateBJ( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, 900 )
endfunction

function Trig_SG_Actions takes nothing returns nothing
    call ForForce( GetPlayersAll(), function Trig_SG )
endfunction

//===========================================================================
function InitTrig_Starting_Gold takes nothing returns nothing
    set gg_trg_Starting_Gold = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Starting_Gold, function Trig_SG_Actions )
endfunction
But this would, because of the timer, not because of the Group:
JASS:
function Trig_Gold_Over_Time takes nothing returns nothing
    call AdjustPlayerStateBJ( 25, GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD )
endfunction

function Trig_Gold_Over_Time_Actions takes nothing returns nothing
    call ForForce( GetPlayersAll(), function Trig_Gold_Over_Time )
endfunction

//===========================================================================
function InitTrig_Gold_Over_Time takes nothing returns nothing
    set gg_trg_Gold_Over_Time = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Gold_Over_Time, 30.00 )
    call TriggerAddAction( gg_trg_Gold_Over_Time, function Trig_Gold_Over_Time_Actions )
endfunction
Am I correct?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Nope, it's the group that leaks.

The event doesn't leak.

In other news, BJs are nasty --

GetPlayersAll() can be replaced with bj_FORCE_ALL_PLAYERS

TriggerRegisterTimerEventPeriodic( trigger, time ) can be replaced with TriggerRegisterTimerEvent( trigger, time, true )

AdjustPlayerStateBJ( amount, player, resource) can be replaced with SetPlayerState( player, resource, GetPlayerState( player, resource ) + amount )
 
Level 6
Joined
Jun 30, 2006
Messages
230
@paskovich

It's actually NOT converted GUI. It's just simple and I'm not an expert by any standards in JASS. I learned JASS (somewhat) by converting triggers I understood, which is why it looks like converted GUI. Even the equals signs are the same amount. I just felt like I should copy their style, dunno why.

I wasn't entirely sure where to stick this thread because although the code is done in JASS, the question was not about JASS itself, so I didn't know where to stick it.

So, if I understand this right, all players group does in fact leak? I've read several things saying it didn't, but what do I know?

So this shouldn't leak (I think):
JASS:
function Gold_Over_Time takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD ) + 25 )
endfunction
function Gold_Over_Time_Actions takes nothing returns nothing
    call ForForce( bj_FORCE_ALL_PLAYERS, function Gold_Over_Time )
endfunction
//===========================================================================
function InitGold_Over_Time takes nothing returns nothing
    set gg_trg_Gold_Over_Time = CreateTrigger( )
    call TriggerRegisterTimerEvent( gg_trg_Gold_Over_Time, 30, true )
    call TriggerAddAction( gg_trg_Gold_Over_Time, function Gold_Over_Time_Actions )
endfunction
Edit:Made it less "GUI"-like, for pask mostly.
 
Last edited:
Level 6
Joined
Jun 30, 2006
Messages
230
Groups in general leak, which I know. I'd heard that the all players group does not leak, but I don't know for sure. Does it, or does it not, leak?
 
Level 6
Joined
Jun 30, 2006
Messages
230
Also, this code validates, but doesn't work:
JASS:
function GoldOverTime takes nothing returns nothing
    call SetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD, GetPlayerState( GetEnumPlayer(), PLAYER_STATE_RESOURCE_GOLD ) + 25 )
endfunction

function GoldOverTimeActions takes nothing returns nothing
    call ForForce( bj_FORCE_ALL_PLAYERS, function GoldOverTime )
endfunction

//===========================================================================
function InitTrig_GoldOverTime takes nothing returns nothing
    set gg_trg_GoldOverTime = CreateTrigger()
    call TriggerRegisterTimerEvent( gg_trg_Gold_Over_Time, 30, true )
    call TriggerAddAction( gg_trg_GoldOverTime, function GoldOverTimeActions )
endfunction
Every 30 seconds you are supposed to get 25 more gold. Help?
I worked before made the changes purplepoot said to make. I'm thinking I used something wrong?
 
Last edited:
Level 6
Joined
Jun 30, 2006
Messages
230
Hmmm... recoded from scratch and it works, reposted it above. Must have had a typo somewhere, but strangely the parser gave no errors. Thanks.

So, to sum it up:
1. Don't use BJ's if possible
2. bj_FORCE_ALL_PLAYERS doesn't leak, but all other groups do.

Question! Why exactly are the BJ's bad? You merely said nasty and didn't explain, but I'd like to know why. Inefficient? Leak? What?

For example, SetUnitVertexColor and SetUnitVertexColorBJ:
JASS:
native          SetUnitVertexColor  takes unit whichUnit, integer red, integer green, integer blue, integer alpha returns nothing
JASS:
function SetUnitVertexColorBJ takes unit whichUnit, real red, real green, real blue, real transparency returns nothing
    call SetUnitVertexColor(whichUnit, PercentTo255(red), PercentTo255(green), PercentTo255(blue), PercentTo255(100.0-transparency))
endfunction

Obviously I see the difference between the two as far as what they do, but are BJ's merely inefficient? I see no leaks or anything, but perhaps this is a bad example?
 
Level 11
Joined
Jul 12, 2005
Messages
764
No, Blue_Jeans, that's a perfect example of a BJ. It is inefficient, as you said. The BJ calls the native, someimes with a little maths inside, but sometimes simply changing the order of parameters (like "*Swapped()" functions). But why use BJ, when you can call the native instantly? Also, there are functions like PolarProjectionBJ, that use mathematical calculation to get the target point of the previous point. But it uses locations as a parameter, and as a return value, but the whole thing can be done with coordinates. BJs are a waste of CPU speed.

PS: Don't overreact, but this thread has nothing to do with spells or systems, but it included Jass, so I moved it to the right section. That's all, no problem.
 
Status
Not open for further replies.
Top