Why is this code leaking? Please,help T_T

newtonrox

Member
Reaction score
2
this is a really simple code and i don't know what it's leaking here! how is that possible? My map always crashes, telling there's no memory to execcute some code.
Then, I ended up with this conclusion after disabling trigger by trigger and running the map. Disabling this trigger makes my map run smoothly by 3 hours(had enough of testing).
local variables are set to null. i can't find anything else here.
pls help ^^

JASS:
function Trig_Ability_On_Func002A takes nothing returns nothing
local unit U = GetEnumUnit()


if  ( IsUnitType(U, UNIT_TYPE_STRUCTURE) == false ) then    
  

    if  ( GetUnitRace(U) == RACE_DEMON )  then
                
         call UnitAddAbility(U, 'A002')
   
    else
        
        call UnitAddAbility(U, 'A003')   
    endif
  
endif

set U = null
endfunction



function Trig_Ability_On_Actions takes nothing returns nothing
local group G = GetUnitsInRectAll(bj_mapInitialPlayableArea)
            
          
             call ForGroup(G, function Trig_Ability_On_Func002A )
             call DestroyGroup(G)
            set G = null



endfunction

//===========================================================================
function InitTrig_Ability_On takes nothing returns nothing
    set gg_trg_Ability_On = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Ability_On, function Trig_Ability_On_Actions )
endfunction


PS: there's a second trigger that takes away those abilities from the units affected by this trigger. So, this trigger is called in a periodic event by a third trigger.
 

Naga'sShadow

Ultra Cool Member
Reaction score
49
Well if it's a memory error the problem is likely in your for group, as that's a loop and it must be going infinite. It's probably this GetUnitRace() that's the problem.
 

newtonrox

Member
Reaction score
2
Does GetUnitRace() leaks?

even if it's a loop, the condition to get out the loop is when there's no unit left to be picked in the group, right?
 

Jesus4Lyf

Good Idea™
Reaction score
397
^That guy is incorrect. (Naga'sShadow)

>GetUnitsInRectAll(bj_mapInitialPlayableArea)
Returns a group created in a local variable, doesn't it? ;)

That means the handle reference is never nulled, and the handle id leaks.

Also, it does a nasty memory leak because it enumerates with a null filter, if I recall that BJ correctly.
 

newtonrox

Member
Reaction score
2
now i'm confused. XD
so what am i supposed to do in this situation?
not assign a variable to GetUnitsInRectAll(bj_mapInitialPlayableArea)?
use a global? use other method?
 

uberfoop

~=Admiral Stukov=~
Reaction score
177
now i'm confused. XD
so what am i supposed to do in this situation?
not assign a variable to GetUnitsInRectAll(bj_mapInitialPlayableArea)?
use a global? use other method?
Well, I'm not sure what the problem is. However, by what J4L said, and looking at the BJ you're using, a better method right off the bat would be:


-Impliment BoolexprUtils

-Create a permanent global group or two for instant enumeration purposes. This group is to be created at map init and never destroyed. Instead, use GroupClear(<GlobalGroupName>) whenever you finish using it.

-Change your enumeration to something native. ie:
JASS:

call GroupEnumUnitsInRect(&lt;GlobalGroupName&gt;,&lt;Name of Rect&gt;,BOOLEXPR_TRUE)




That way, you don't have to worry about destroying groups, you don't have boolexpr null leaks, and your code is cleaner.


edit: J4L seems to have beaten me to it :)
 

newtonrox

Member
Reaction score
2
omg boolean variables leak too? XD
But how do i impliment BoolexprUtils? should i just paste in a trigger that runs at map init?

i've never used library neither have declared global variables(i create them in GUI)

thx for the help ^^
 

newtonrox

Member
Reaction score
2
i'm searching for a library tutorial XD
does anyone have a good link?
should it go inside a scope(whatever it is) ?
i always thought boolexpr was the same thing! omg! T_T
 

Jesus4Lyf

Good Idea™
Reaction score
397
Here's your tutorial:
Copy paste it into a new, empty JASS trigger. Then forget about it. :)

WC3C doesn't have the same requirements as us - such as an implementation instruction set on all resources. <_<

Anyway, that library is only used here:
>call GroupEnumUnitsInRect(<GlobalGroupName>,<Name of Rect>,BOOLEXPR_TRUE)
 

newtonrox

Member
Reaction score
2
thx for the help man!
I've just started learning P.O.O. in college
haha all i know is what a private and a public statement does XDD
 

newtonrox

Member
Reaction score
2
well, i created a trigger called Library,converted it to custom text, erased everything was inside the trigger and pasted the following code:
JASS:
library BoolexprUtils initializer init
    globals
        boolexpr BOOLEXPR_TRUE=null
        boolexpr BOOLEXPR_FALSE=null
    endglobals

    private function rettrue takes nothing returns boolean
        return true
    endfunction

    private function retfalse takes nothing returns boolean
        return false
    endfunction

    private function init takes nothing returns nothing
        set BOOLEXPR_TRUE=Condition(function rettrue)
        set BOOLEXPR_FALSE=Condition(function retfalse)
    endfunction
endlibrary


after that, i save the map and WorldEdit does not complain.
but when i try to test the map, it does not load and it leads me to the default start screen of War3.
I'm using jassnewgenpack5c.

Does anyone know if i'm missing something here? thx
 

newtonrox

Member
Reaction score
2
Didn't work.
If I create a trigger and paste the content of the library, i'm able to save the game.
But when disable the trigger and try to enable it again, the Editor complains.
Here's an image of my problem:

http://img29.imageshack.us/i/omgpe.jpg/
What appears in this image is everything that's inside the trigger. I don't know if it's right to erase it but I've deleted the part of the code that initializes the trigger ( that CreateTrigger() stuff ). Is that correct?


pls help, cuz i've never used libraries and i did use the search tool but, nothing I've read, helps.

Does anyone knows if I forgot to enable anything in newgen?
thx in advance!
 

newtonrox

Member
Reaction score
2
Well I gave up on the library.
but then i made the BoolExpr thing inside the trigger.

JASS:
//=======================  Filtro do GroupEnumUnitsInRect()==================//
function RetTrue takes nothing returns boolean
 return true
endfunction
//===========================================================================//



function Trig_Ability_On_Func002A takes nothing returns nothing
local unit U = GetEnumUnit()


if  ( IsUnitType(U, UNIT_TYPE_STRUCTURE) == false ) then    
  

    if  ( GetUnitRace(U) == RACE_DEMON )  then
                
         call UnitAddAbility(U, &#039;A002&#039;)
   
    else
        
        call UnitAddAbility(U, &#039;A003&#039;)   
    endif
  
endif

set U = null

endfunction



function Trig_Ability_On_Actions takes nothing returns nothing
local boolexpr Bool = null

             set Bool = Condition(function RetTrue)

             call GroupEnumUnitsInRect(udg_ALLMAP,bj_mapInitialPlayableArea,Bool) 
            
          
             call ForGroup(udg_ALLMAP, function Trig_Ability_On_Func002A )
             call GroupClear(udg_ALLMAP)
             set Bool = null
   


endfunction


//===========================================================================
function InitTrig_Ability_On takes nothing returns nothing
    set gg_trg_Ability_On = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Ability_On, function Trig_Ability_On_Actions )
endfunction


And I'm still having memory crash. Is still there any leak?

This problem is driving me crazy already! T_T


I've just read another thread saying boolexpr null variables leaks when used as a parameter of GroupEnumUnitsInRect( ).
So as i can't make libraries, I guess I need to create a global boolexpr at map init and set it as true right?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top