• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[vJASS] Code Leaking: CreateDestructable

Status
Not open for further replies.
Level 11
Joined
Jun 30, 2008
Messages
580
Hello,

I don't understand how this code can still be leaking. I have isolated the CreateDestructable function to be leaking, even though I remove the destructable after I use it, and I null the local variable, I also store the GetRectX and GetRectY globally.

Here is the code:

JASS:
private function NextChoice takes nothing returns nothing
        local integer ary = GetPlayerId(GetTriggerPlayer())
        local CharDat dat = LoadInteger(CD, ary, 1)
        local destructable d = null
        call UnitRemoveAbility(Display[ary], LoadInteger(Options, dat.Attribute, dat.Choices[dat.Attribute]))
        if (dat.Choices[dat.Attribute] < MaxChoice[dat.Attribute]) then
            set dat.Choices[dat.Attribute] = dat.Choices[dat.Attribute]+1
        else
            set dat.Choices[dat.Attribute] = 1
        endif
        if (dat.Attribute == 1) or (dat.Attribute == 2) then
            set d = CreateDestructable(LoadInteger(Options, dat.Choices[2], dat.Choices[1]), dat.rX, dat.rY, 0.0, 0.0, 0)
            call IssueTargetOrder( Display[ary], "grabtree", d)
            call RemoveDestructable(d)
            set d = null
        endif
        call UnitAddAbility(Display[ary], LoadInteger(Options, dat.Attribute, dat.Choices[dat.Attribute]))
        call MultiboardSetItemValue(dat.mbitemB[dat.Attribute], LoadStringBJ(dat.Attribute, dat.Choices[dat.Attribute], OStrings))
    endfunction
 
Level 11
Joined
Jun 30, 2008
Messages
580
It isn't that, I have the item objects stored globally so I don't create a new one every time I call that. I commented out everything and found it was the CreateDestructable. Is it the fact that I'm using War Club on the destructable that is not allowing me to remove it?
 
What does the destructable look like? Some models never fully disappear take a long time to be removed. Does the descructable have a custom model file?

Can you describe the leak a little better? What is leaking, is it the RAM? Is it causing framerate drop? Leaks usually take a very long time to show their evil, like thousands of leaks we're talking about here.
 
Level 11
Joined
Jun 30, 2008
Messages
580
Well, it is causing my handles to go up by 30 to 100 handles every time that function is called, and it is called quite a bit, so it ends up going up about 10k after all players are done using it.

It is a dummy destructable, so it has no model file.
 
The handles will continue to go up until around the 1000 handles mark, and then the handle count will drop back down.

It doesn't drop instantly. If you call "Location(0,0)" it will have a handle ID for example 0x100000. But if you remove it and then call Location(0,0) again it will have a handle ID of 0x100001.

What are you using to count your handles? It's almost certainly an outdated system, as handle counters don't work since 1.23 or so.
 
Level 11
Joined
Jun 30, 2008
Messages
580
JASS:
ibrary HandleCounter

globals
    private constant integer safety = 50
endglobals

function CountHandles takes nothing returns integer
    local integer i = 0
    local integer i2 = 0
    local integer space = 0
    local integer space2 = 0
    local integer count = 0
    local location array loc
    local integer hid = 0
    local integer hid2
    loop
        set loc[i] = Location(0., 0.)
        set hid2 = GetHandleId(loc[i]) - 0x100000
        if hid2 == hid + 1 or hid == 0 then
            set space = space + 1
            set space2 = space2 + 1
        else
            set space2 = 0
        endif
        set hid = hid2
        set i = i + 1
        set count = hid
        exitwhen space2 == safety
    endloop
    loop
        exitwhen i2 > i
        call RemoveLocation(loc[i2])
        set loc[i2] = null
        set i2 = i2 + 1
    endloop
    return count - space - safety - 1
endfunction

endlibrary

This is the handle counter I use. And the handles aren't going down. Been waiting about 5 minutes and they are staying the same at over 1k
 
Status
Not open for further replies.
Top