HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

What the fart does this mean?

05-16-2007, 11:43 AM#1
Toink
"Double free of group in "GroupEnumUnitsInLine" "

... Eh?

Here's tehhh code.

Collapse JASS:

function GroupEnumUnitsInLine takes group g, real x1, real y1, real x2, real y2, real width returns nothing
    local real angle = Atan2(y2-y1,x2-x1)
    local real dist = SquareRoot( (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1) )
    local real cdist = 0
    local group temp
    loop
        exitwhen (cdist > dist)
        set temp = CreateGroup()
        call GroupEnumUnitsInRange(temp,x1,y1,width/2,null)
        set bj_wantDestroyGroup = true
        call GroupAddGroup(temp,g)
        set x1 = x1+((width/4)*Cos(angle))
        set y1 = y1+((width/4)*Sin(angle))
        set cdist = cdist + (width/4)
    endloop
    call DestroyGroup(temp)
    set temp = null
endfunction
05-16-2007, 12:38 PM#2
Silvenon
I don't understand what do you mean

This code should add units in line to the given group
05-16-2007, 12:41 PM#3
Toink
It DOES add units in the group >_>

Whenever I test it in debug mode that double free thing error shows up.
05-16-2007, 12:46 PM#4
Rising_Dusk
You're destroying the group twice.

Collapse JASS:
function GroupEnumUnitsInLine takes group g, real x1, real y1, real x2, real y2, real width returns nothing
    local real angle = Atan2(y2-y1,x2-x1)
    local real dist = SquareRoot( (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1) )
    local real cdist = 0
    local group temp
    loop
        exitwhen (cdist > dist)
        set temp = CreateGroup()
        call GroupEnumUnitsInRange(temp,x1,y1,width/2,null)
        set bj_wantDestroyGroup = true
        call GroupAddGroup(temp,g)
        set x1 = x1+((width/4)*Cos(angle))
        set y1 = y1+((width/4)*Sin(angle))
        set cdist = cdist + (width/4)
    endloop
    call DestroyGroup(temp)
    set temp = null
endfunction
Collapse JASS:
function GroupAddGroup takes group sourceGroup, group destGroup returns nothing
    // If the user wants the group destroyed, remember that fact and clear
    // the flag, in case it is used again in the callback.
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    set bj_groupAddGroupDest = destGroup
    call ForGroup(sourceGroup, function GroupAddGroupEnum)

    // If the user wants the group destroyed, do so now.
    if (wantDestroy) then
        call DestroyGroup(sourceGroup)
    endif
endfunction
Because silly you set bj_wantDestroyGroup = true.
05-16-2007, 01:08 PM#5
Toink
Oh right! I was looking inside that function. Ugh silly me. :D Thanks.
05-16-2007, 04:44 PM#6
blu_da_noob
Instead of creating a new group on each iteration, use the same group and clear it each time (and obviously remove your wantdestroy stuff). It's totally unnecessary.