• 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.

[JASS] Looking for leaking BJs

Status
Not open for further replies.
Level 8
Joined
Jul 10, 2008
Messages
353
I got so tired of battling with stupid cmemblock.cpp that i decided to replace all BJ with one that do not leak.


Is there any list of all known leaking BJs?

Would be nice if there are any already made BJ replacements. The more the merrier, I will do what i cant find.
 
Level 8
Joined
Jul 10, 2008
Messages
353
Very good link, but I am more interested to know if stuff like this do leak? :


UnitHasBuffBJ
AddItemToStockBJ
AddResourceAmountBJ
UnitApplyTimedLifeBJ
IsTerrainPathableBJ
etc etc

Most BJs that use a local declared local handle variable leak due to the associated bug. The current fix is to null the variable before return, or if the function cannot trigger any other events then a global variable can be used instead.
Can you explain this handle leak more? I mean if handles can leak then pretty much everything leaks? o.0

example1:
JASS:
function UnitApplyTimedLifeBJ takes real duration, integer buffId, unit whichUnit returns nothing
    call UnitApplyTimedLife(whichUnit, buffId, duration)
endfunction
Does the above leak a unit?
JASS:
unit whichunit

example2
JASS:
function IsTerrainPathableBJ takes location where, pathingtype t returns boolean
    return IsTerrainPathable(GetLocationX(where), GetLocationY(where), t)
endfunction

Does the above leak a location?
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,287
Can you explain this handle leak more? I mean if handles can leak then pretty much everything leaks? o.0
Local declared local handle variable reference counter leak on return bug. The name is pretty self-explanatory. Handles referenced by a local handle variable declared with the "local" keyword are not cleaned up properly on function return causing a reference count to leak. Due to the reference counter having a leak, the handle id cannot ever be recycled as it will always think 1 or more references to it exist despite no actual references existing.

It is a bug because parameter declared local handle variables do not suffer from this and do correctly decrement the reference counter on return (or maybe they do not increment it in the first place? hard to prove). In any case the current fix is to make sure to null all local declared local handle variables before the function returns.
 
Level 8
Joined
Jul 10, 2008
Messages
353
I see, didint fully understood then.

example:
Its known this leaks:
JASS:
function SmartCameraPanBJ takes player whichPlayer, location loc, real duration returns nothing
    local real dist
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        set dist = DistanceBetweenPoints(loc, GetCameraTargetPositionLoc())
        if (dist >= bj_SMARTPAN_TRESHOLD_SNAP) then
            // If the user is too far away, snap the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0)
        elseif (dist >= bj_SMARTPAN_TRESHOLD_PAN) then
            // If the user is moderately close, pan the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
        else
            // User is close enough, so don't touch the camera.
        endif
    endif
endfunction
If the leak is not on that location handle, then where is it?
 
Level 8
Joined
Jul 10, 2008
Messages
353
I see so, GetCameraTargetPositionLoc() leaks
so if for example i had added this:
JASS:
function SmartCameraPanBJ takes player whichPlayer, location loc, real duration returns nothing
    local real dist
    local location loc01=GetCameraTargetPositionLoc() //<- added
    if (GetLocalPlayer() == whichPlayer) then
        // Use only local code (no net traffic) within this block to avoid desyncs.

        set dist = DistanceBetweenPoints(loc, loc01) //<- added
        if (dist >= bj_SMARTPAN_TRESHOLD_SNAP) then
            // If the user is too far away, snap the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), 0)
        elseif (dist >= bj_SMARTPAN_TRESHOLD_PAN) then
            // If the user is moderately close, pan the camera.
            call PanCameraToTimed(GetLocationX(loc), GetLocationY(loc), duration)
        else
            // User is close enough, so don't touch the camera.
        endif
    endif
    call RemoveLocation(loc01) //<- added, technically this can be added if i renamed the function i guess.
    set loc01=null //<- added
endfunction
Would this remove the leak?
 
Level 24
Joined
Aug 1, 2013
Messages
4,658
Good luck with that.
Leaks and desyncs are not bad functions, it is a bad programmer.
CreateUnit() leaks, CreateGroup() leaks, Location() leaks, CreateTimer() leaks.
That is why you have RemoveUnit(), DestroyGroup(), RemoveLocation(), DestroyTimer().

For desyncs the same, if you mess with agents but dont do it for all players, your clients fall out of sync, so they disconnect.

It is the programmer who has to remove the data when it's scope ended and to make sure that data manipulation is synchronized (for non-local data at least).

Ofcourse, you can fix PolledWait()'s and GetUnitsOfTypeIdAll()'s handle leak, or fix something else that would cause such things.
In the end, it is still you that should be programming right and both of those functions are not really nice to use.
 
Level 8
Joined
Jul 10, 2008
Messages
353
Good luck with that.
Leaks and desyncs are not bad functions, it is a bad programmer.
CreateUnit() leaks, CreateGroup() leaks, Location() leaks, CreateTimer() leaks.
That is why you have RemoveUnit(), DestroyGroup(), RemoveLocation(), DestroyTimer().

For desyncs the same, if you mess with agents but dont do it for all players, your clients fall out of sync, so they disconnect.

It is the programmer who has to remove the data when it's scope ended and to make sure that data manipulation is synchronized (for non-local data at least).

Ofcourse, you can fix PolledWait()'s and GetUnitsOfTypeIdAll()'s handle leak, or fix something else that would cause such things.
In the end, it is still you that should be programming right and both of those functions are not really nice to use.
What i got from that, is that blizzard programmers wanted to do their job as fast as possible, which didnt include custom map support. Anyway, am the type of guy that believe nothing is impossible for the willing. And i applaud your eagerness to help, but i didnt say am gonna fix all leaks, just the ones in blizzard.j (which i already did by now). Wasnt even tricky or hard, just a lot of work.
 
Level 8
Joined
Jul 10, 2008
Messages
353
So i inserted the modified blizzard.j into the map. But there are some issues and am not even sure if they are related.

1. When a bot hosts the map, I always redownload it (over and over) and then i get kicked right after dl has finished.
2. Only way to play the map is to host it myself.
3. Am using vex optimizer and i have checked optimized other .j, don't know if that affected blizzard.j in some wierd way.
4. Single player the map plays normally, also map plays normally online if i host and play it alone.

You guys know of any known issue that could cause this?
 
Status
Not open for further replies.
Top