HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Help me find a leak

03-12-2008, 08:16 PM#1
CommanderZ
I have this spell
Collapse JASS:
function Trig_Annihilator_Dragon_Nexus_freeze_Actions takes nothing returns nothing
    local group g=GetUnitsOfTypeIdAll('h00E')
    local unit u
    local unit d
    local group g2
    local unit u2
    local player p=Player(0)
    
    loop
        set u = FirstOfGroup(g)
        exitwhen u==null
        
        set g2=CreateGroup()
        call GroupEnumUnitsInRange(g2,GetUnitX(u),GetUnitY(u),400,null)
        loop
            set u2 = FirstOfGroup(g2)
            exitwhen u2==null

            if GetUnitAbilityLevel(u2,'B00L')==0 then
                set d=CreateUnit(p,'h002',GetUnitX(u2),GetUnitY(u2),270.)
                call UnitAddAbility(d,'A03N')
                call IssueTargetOrder(d,"thunderbolt",u2)
                call UnitApplyTimedLife(d,'B000',0.40)    
            endif
        
            call GroupRemoveUnit(g2,u2)
        endloop
        call DestroyGroup(g2)
             
        call GroupRemoveUnit(g,u)
    endloop 
    call DestroyGroup(g)
    set g=null
    set g2=null
    set u=null
    set u2=null
    set d=null
    set p=null
endfunction
It should cast a thunderbolt based spell on all units in range of 400 of any 'h00E'. It works, but after cca one minute of running this function every 1 sec, the game starts to freeze. After some time it freezes completely, so somewhere in this code must be a serious leak.

Thanks in advance, rep is awaiting

PS: 'B00L' is the buff the thunderbolt gives. Just to prevent useless double casts.
03-13-2008, 02:56 AM#2
Pyrogasm
It could just be that the sheer amount of groups you create is too much for the game to handle... I'd do this instead:
Collapse JASS:
function Trig_Annihilator_Dragon_Nexus_freeze_Actions takes nothing returns nothing
    local group g=GetUnitsOfTypeIdAll('h00E')
    local unit u
    local unit d
    local group g2 = CreateGroup() //Initialized as CreateGroup()
    local unit u2
    local player p=Player(0)
    
    loop
        set u = FirstOfGroup(g)
        exitwhen u==null
        
        //No setting of g2
        call GroupEnumUnitsInRange(g2,GetUnitX(u),GetUnitY(u),400,null)
        loop
            set u2 = FirstOfGroup(g2)
            exitwhen u2==null

            if GetUnitAbilityLevel(u2,'B00L')==0 then
                set d=CreateUnit(p,'h002',GetUnitX(u2),GetUnitY(u2),270.)
                call UnitAddAbility(d,'A03N')
                call IssueTargetOrder(d,"thunderbolt",u2)
                call UnitApplyTimedLife(d,'B000',0.40)    
            endif
        
            call GroupRemoveUnit(g2,u2)
        endloop
        //No destroying; the group will be clear also
             
        call GroupRemoveUnit(g,u)
    endloop 
    call DestroyGroup(g)
    set g=null
    set g2=null
    set u=null
    set u2=null
    set d=null
    set p=null
endfunction
03-13-2008, 08:59 AM#3
Anitarf
You forgot to put call DestroyGroup(g2) in the end, though.

The best way to do this would be to simply have two groups in global variables and keep reusing them, without ever destroying them or creating new ones. With vJass, declaring new globals is a piece of cake so this has changed the way we code things considerably.
03-17-2008, 06:42 PM#4
CommanderZ
Thanks you both

But the problem still lasts - this triger makes the game freeze. While it is disabled, everything is alright.
03-17-2008, 10:21 PM#5
Silvenon
Maybe something is wrong with the spell (thunderbolt)? What's 'B000'?

Other than that, I see no reason for the game to freeze, it would take a lot more than group leaks to freeze the game.
03-17-2008, 10:44 PM#6
Strilanc
What calls the function? Maybe ordering the dummy caster to cast the spell is making the trigger run again.
03-18-2008, 03:21 PM#7
CommanderZ
B00L is a modified Stunned buff the modified thunderbold gives.

Here is whole code of the trigger as I have it now:
Collapse JASS:
function Trig_Annihilator_Dragon_Nexus_freeze_Actions takes nothing returns nothing
    local group g=GetUnitsOfTypeIdAll('h00E')
    local unit u
    local unit d
    local group g2=CreateGroup()
    local unit u2
    local player p=Player(0)
    
    loop
        set u = FirstOfGroup(g)
        exitwhen u==null
        
        call GroupEnumUnitsInRange(g2,GetUnitX(u),GetUnitY(u),400,null)
        loop
            set u2 = FirstOfGroup(g2)
            exitwhen u2==null

            if GetUnitAbilityLevel(u2,'B00L')==0 then
                set d=CreateUnit(p,'h002',GetUnitX(u2),GetUnitY(u2),270.)
                call UnitAddAbility(d,'A03N')
                call IssueTargetOrder(d,"thunderbolt",u2)
                call UnitApplyTimedLife(d,'B000',0.40)    
            endif
        
            call GroupRemoveUnit(g2,u2)
        endloop
             
        call GroupRemoveUnit(g,u)
    endloop 
    call DestroyGroup(g)
    call DestroyGroup(g2)
    set g=null
    set g2=null
    set u=null
    set u2=null
    set d=null
    set p=null
endfunction

//===========================================================================
function InitTrig_Annihilator_Dragon_Nexus_freeze takes nothing returns nothing
    set gg_trg_Annihilator_Dragon_Nexus_freeze = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Annihilator_Dragon_Nexus_freeze, 1.00 )
    call TriggerAddAction( gg_trg_Annihilator_Dragon_Nexus_freeze, function Trig_Annihilator_Dragon_Nexus_freeze_Actions )
endfunction
I found everything runs smoothly if I delete the four inmost lines, that summon and manipulate the dummy. I have no idea what is wrong here though - I use the same dummy, same bufs etc. in several spells and everything is allright.
03-18-2008, 04:00 PM#8
RolePlaynGamer
hmm maybe it's this line

Collapse JASS:
call UnitApplyTimedLife(d,'B000',0.40)
Try using
Collapse JASS:
'BTLF'
instead of
Collapse JASS:
'B000'

Your trigger fires every 1 second, and creates a lot of dummies. Maybe you actually dont remove the dummies from the game with 'B000'. try using 'BTLF'
03-18-2008, 05:13 PM#9
CommanderZ
What is BTLF? It is not in the object editor. My B000 is just modified Summoned unit ith removed vis effect.

BTW, I tried the BTLF and it was still the same.
03-18-2008, 05:15 PM#10
RolePlaynGamer
BTLF is the generic expiration timer.
03-19-2008, 02:47 PM#11
Silvenon
Question:

Quote:
Originally Posted by Silvenon
What's 'B000'?

Answer:

Quote:
Originally Posted by CommanderZ
B00L is a modified Stunned buff the modified thunderbold gives.

Do you see a flaw in your answer? :)