Leak Question

newtonrox

Member
Reaction score
2
JASS:
function Trig_Spawn_Basic_Func001Func001C takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetEnumUnit()) == 'h001' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Spawn_Basic_Func001A takes nothing returns nothing
local location A = GetUnitLoc(GetEnumUnit())


    if ( Trig_Spawn_Basic_Func001Func001C() ) then
       if  ( ( GetPlayerState(GetOwningPlayer(GetEnumUnit()), PLAYER_STATE_RESOURCE_FOOD_USED) < 70 ) ) then       
           

call CreateNUnitsAtLocFacingLocBJ( 5, 'h00C', GetOwningPlayer(GetEnumUnit()), A, A )
       endif    
    else
    endif
call RemoveLocation (A)

endfunction

function Trig_Spawn_Basic_Actions takes nothing returns nothing
local group u = GetUnitsInRectAll(GetPlayableMapRect())    
    
    call ForGroup( u, function Trig_Spawn_Basic_Func001A )
    call DestroyGroup(u)
    set u = null
endfunction

//===========================================================================
function InitTrig_Spawn_Basic takes nothing returns nothing
    set gg_trg_Spawn_Basic = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Spawn_Basic, 2.00 )
    call TriggerAddAction( gg_trg_Spawn_Basic, function Trig_Spawn_Basic_Actions )
endfunction


will it leak?
what's the difference between nullifying and removing/destroying a variable?
does GetEnumUnit leak when i call it?
 

Komaqtion

You can change this now in User CP.
Reaction score
469
Wow !!! That inlining really hurts my eyes !!! How can you work with that ???!!!!

Anyways, no it won't leak, though you should null locations if I'm correct...

And the whole trigger can just be like this :

JASS:
function Trig_Spawn_Basic_Func001Func001C takes nothing returns boolean
    return GetUnitTypeId(GetEnumUnit()) == 'h001' ) )
endfunction

function Trig_Spawn_Basic_Func001A takes nothing returns nothing
    local location A = GetUnitLoc(GetEnumUnit())
        if (Trig_Spawn_Basic_Func001Func001C()) and ( ( GetPlayerState(GetOwningPlayer(GetEnumUnit()), PLAYER_STATE_RESOURCE_FOOD_USED) < 70 ) ) then 
            call CreateNUnitsAtLocFacingLocBJ( 5, 'h00C', GetOwningPlayer(GetEnumUnit()), A, A ) 
        endif
    call RemoveLocation (A)
    set A = null
endfunction

function Trig_Spawn_Basic_Actions takes nothing returns nothing
    local group u = GetUnitsInRectAll(GetPlayableMapRect())    
    call ForGroup( u, function Trig_Spawn_Basic_Func001A )
    call DestroyGroup(u)
    set u = null
endfunction

//===========================================================================
function InitTrig_Spawn_Basic takes nothing returns nothing
    set gg_trg_Spawn_Basic = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Spawn_Basic, 2.00 )
    call TriggerAddAction( gg_trg_Spawn_Basic, function Trig_Spawn_Basic_Actions )
endfunction
 

newtonrox

Member
Reaction score
2
thx again man ^^
and yes, location must be set to null
cuz now my map is lagless =D
lol
after 1 hour my map was crashing just because of this variable...
and well, i'm running it for about 20 minutes and it's not laggy anymore =)
 

Exide

I am amazingly focused right now!
Reaction score
448
No need to call 'Trig_Spawn_Basic_Func001Func001C'.
'CreateNUnitsAtLocFacingLocBJ' might as well be: 'CreateNUnitsAtLoc'
 

newtonrox

Member
Reaction score
2
thx as well ^^
after killing 12k units in 55 min
there's really no lag now! XD
is it worthy to set a local unit variable to GetEnumUnit()?
 

Attachments

  • Killing_Overview.jpg
    Killing_Overview.jpg
    147.3 KB · Views: 146

Komaqtion

You can change this now in User CP.
Reaction score
469
Well, yeah since you're using it so much... But that would mean that you need to alter your entire code :(

So use this :D

JASS:
function filter takes nothing returns nothing
    local integer i = 0
    local unit u = GetEnumUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    if GetUnitTypeId(u) == 'h001' and GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_FOOD_USED) < 70 then
        loop
        exitwhen i >= 5
            call CreateUnit(GetOwningPlayer(u), 'h00C', x,y, bj_UNIT_FACING)
            set i = i + 1
        endloop
    endif
    set u = null
endfunction

function Actions takes nothing returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
    call ForGroup(g, function filter)
    call DestroyGroup(g)
    set g = null
endfunction

//===========================================================================

function InitTrig_Spawn_Basic takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(t, 2.)
    call TriggerAddAction(t, function Actions)
endfunction
 

newtonrox

Member
Reaction score
2
nice,so that's how "create n units bj" works ^^

hmmm this "filter" function...
i see it in lots of codes here in the forum
is it a normal condition fuction? i mean, what's the idea for it? its point...
oh and don't you have to nullify the values of X and Y ( is this called offset in english? the points in the vertical and horizontal axis)?


and can i replace bj_mapInitialPlayableArea for GetPlayableMapRect()?
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
this "filter" function...
is it a normal condition fuction? i mean, what's the idea for it?

"filter" is just a name, players tend to use names that point on what are they doing

in this case, filter is not a good name, because ForGroup() function runs actions for each unit in the group and has nothing to do with "filtering"

anyway, it's always better to create just 1 global group at map init

so instead of this:

JASS:
function Actions takes nothing returns nothing
    local group g = CreateGroup()
    call GroupEnumUnitsInRect(g, bj_mapInitialPlayableArea, null)
    call ForGroup(g, function filter)
    call DestroyGroup(g)
    set g = null
endfunction


do this:

JASS:
function Actions takes nothing returns nothing
    call GroupEnumUnitsInRect(udg_g, bj_mapInitialPlayableArea, Condition(function filter))
endfunction


I don't know how you declare globals in Jass... (I know in vJass)

also change the filter function to this:

JASS:
function filter takes nothing returns boolean // notice the return
    local integer i = 0
    local unit u = GetFilterUnit() // not GetEnumUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    if GetUnitTypeId(u) == 'h001' and GetPlayerState(GetOwningPlayer(u), PLAYER_STATE_RESOURCE_FOOD_USED) < 70 then
        loop
        exitwhen i >= 5
            call CreateUnit(GetOwningPlayer(u), 'h00C', x,y, bj_UNIT_FACING)
            set i = i + 1
        endloop
    endif
    set u = null

    return false // always return false so the group will be "empty"
endfunction


in this case "filter" is a good name because we are filtering :p
this is a faster way, use it always if you gonna group units instantly

and can i replace bj_mapInitialPlayableArea for GetPlayableMapRect()?

if I'm correct, GetPlayableMapRect() is a BJ that actually returns bj_mapInitialPlayableArea so yeah, but it's pointless
 

newtonrox

Member
Reaction score
2
wait, i'm noob at jass XD
i've searched for this function "GroupEnumUnitsInRect" in NewGen fuction list and didn't find any explanation about it.
This function is the "Pick every unit and do action" from GUI right (i'm still converting GUI into jass when i begin any trigger =p)?

and when you return false to its boolexpr parameter it leaves the group as empty(nullyfied) after the loop?
sry for my noobness...
 

Dinowc

don't expect anything, prepare for everything
Reaction score
223
i'm still converting GUI into jass when i begin any trigger =p

I never learned Jass that way

it just makes junk of a code

if you're still new in Jass then start learning vJass instead (there is a nice tutorial about it)

when you return false to its boolexpr parameter it leaves the group as empty(nullyfied) after the loop?
yes
 

Viikuna

No Marlo no game.
Reaction score
265
He is right. Learning from converted GUI can be a pain in the ass, because its pretty messy and terrible and everything.

People have different way sof learning, though. I always learned by example, so I just read other peoples codes to find out how they do their stuff.

edit. Komaqtion you should know that calling GroupEnum for temporary group leaks, which is why we never use DestroyGroup, but recycle our groups instead. Dinowc´s method is the right way to do this, one global groups is everything you need for your GroupEnum needs.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/
  • The Helper The Helper:
    I think we need to add something to the bottom of the front page that shows the Headline News forum that has a link to go to the News Forum Index so people can see there is more news. Do you guys see what I am saying, lets say you read all the articles on the front page and you get to the end and it just ends, no kind of link for MOAR!

      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