HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

struct error

05-10-2007, 03:51 AM#1
zen87
I was trying to make some system using struct, but an error has showed up,

Code:
Double free of type : somelibrary__somestruct

what does this mean ?

hmm btw this is my code of the system

Hidden information:
Collapse JASS:
library EffectSystem requires CasterSystem
globals

  //Maxinum number of effects for circular effect and spiral effect, if you
  //create an effect with a number >= MaxEffectNumber will cause an error when
  //saving, note that the smaller MaxEffectNumber will allow the system to
  //run faster.

    private constant integer MaxEffectNumber  =  19 //minimum effect will be 18

endglobals
//===========================================================================
//Private Structs and Globals
//===========================================================================
//structs
private struct SpiralData
    unit target = null              //affected target
    unit array u[MaxEffectNumber]   //dummy unit
    real array a[MaxEffectNumber]   //dummy angle
    effect array e[MaxEffectNumber] //effects
    integer id                      //data id
    real l_spd                      //linear spd
    real c_spd                      //circular spd
    real l                          //current radius
    real r                          //radius
    boolean has_e = false           //has effect ?
    integer n                       //effect number
endstruct

private struct CircData //in progress, pls ignore this
    unit target
    real c_spd
    real r
    integer n
endstruct

//globals
globals
    private timer             T                 = CreateTimer()
    private SpiralData array  SD
    private CircData array    CD
    private integer           TotalSpiral     = 0
    private integer           TotalCirc       = 0 //in progress, pls ignore this
endglobals


//===========================================================================
//Mathematics Calculations
//===========================================================================
private function PolarProjectionX takes real x, real dist, real angle returns real
    return x+(dist)*Cos((angle)*0.017453)
endfunction
//! define PolarProjectionX(x,dist,angle) (x+(dist)*Cos((angle)*0.017453))

private function PolarProjectionY takes real y, real dist, real angle returns real
    return y + dist*Sin(angle*0.017453)
endfunction
//! define PolarProjectionY(y,dist,angle) (y+(dist)*Sin((angle)*0.017453))


//===========================================================================
//Killing Effects
//===========================================================================
function DestroySpiralEffect takes SpiralData sd returns nothing
    loop
        if sd.has_e then
            call DestroyEffect(sd.e[sd.n])
        endif
        call RecycleCaster(sd.u[sd.n])
        set sd.n = sd.n - 1
        exitwhen sd.n < 1
    endloop
    set SD[sd.id] = SD[TotalSpiral] //moving last effect to this effect
    set TotalSpiral = TotalSpiral - 1
    call sd.destroy()
endfunction


//===========================================================================
//Effect's Loops
//===========================================================================

//I'm currently working on the spiral data, so pls ignroe the circ data for now >.<
private function EffectLoops takes nothing returns nothing
 local SpiralData sd
 local CircData cd
 local real radius
 local real x
 local real y
 local real x2
 local real y2
 local real a
 local integer number
 local integer n = TotalSpiral+TotalCirc
 local integer i
 local integer s
    loop
        if TotalSpiral>0 then
            set i = 1
            loop
                set sd = SD[i]
                set radius = sd.r
                if GetWidgetLife(sd.target)>0.405 and sd.target!=null then
                    if (sd.l>radius) or (sd.l<0) then
                        call DestroySpiralEffect(sd)
                        set i=i-1
                    else
                        set s = sd.n
                        set x = GetUnitX(sd.target)
                        set y = GetUnitY(sd.target)
                        set sd.l = sd.l+sd.l_spd
                        loop
                            set a = sd.a[s]+sd.c_spd
                            set x2=PolarProjectionX(x,sd.l,a)
                            set y2=PolarProjectionY(y,sd.l,a)
                            call CS_MoveUnit(sd.u[s],x2,y2)

                            if sd.c_spd > 0 then
                                call SetUnitFacingTimed(sd.u[s],(a+90),0.035)
                            else
                                call SetUnitFacingTimed(sd.u[s],(a-90),0.035)
                            endif

                            if a > 360 then
                                set a = a-360
                            elseif a < -360 then
                                set a = a+360
                            endif

                            set sd.a[s] = a
                            set s=s-1
                            exitwhen s<1
                        endloop
                    endif
                else
                    call DestroySpiralEffect(sd)
                    set i=i-1
                endif
                set i=i+1
                set n=n-1
                exitwhen i>TotalSpiral
            endloop
        endif

        if TotalCirc>0 then
            set i = TotalCirc
            loop
                exitwhen true
            endloop
            set i=i+1
            set n=n-1
        endif

        exitwhen n<1
    endloop

    if (TotalSpiral+TotalCirc) < 1 then
        call PauseTimer(T)
        debug call BJDebugMsg("effect timer paused")
    endif
endfunction

private function CheckLoopTimer takes nothing returns nothing
    if (TotalSpiral+TotalCirc) < 1 then
        call TimerStart(T,0.035,true,function EffectLoops)
        debug call BJDebugMsg("effect timer started")
    endif
endfunction

//===========================================================================
//Spiral Effects
//===========================================================================
function CreateSpiralEffect takes string model, unit target, integer r, integer g, integer b, integer number, real scale, real radius, real linearspd, real circularspd, integer repeats, boolean expands returns SpiralData
 local SpiralData sd = SpiralData.create()
 local real a
 local real x = GetUnitX(target)
 local real y = GetUnitY(target)
 local real x2
 local real y2
 local integer n = 1

    if number<=0 then
        call BJDebugMsg("Effect System Error, number is <= 0")
    else
        set a = 360/number
    endif

    if expands then
        set x2=x
        set y2=y
        set sd.l = 0
        set sd.l_spd = (linearspd*0.035)
    else
        set sd.l = radius
        set sd.l_spd = (-linearspd*0.035)
    endif

    set sd.target = target
    set sd.n = number
    set sd.r = radius
    set sd.c_spd = (Atan2(circularspd*0.035,radius)*57.2958)

    loop
        set sd.u[n] = GetACaster()
        set sd.a[n] = a*n
        if not expands then
            set x2=PolarProjectionX(x,radius,(sd.a[n]))
            set y2=PolarProjectionY(y,radius,(sd.a[n]))
        endif
        call CS_MoveUnit(sd.u[n],x2,y2)
        if model != null and model != "" then
            set sd.e[n] = AddSpecialEffectTarget(model,sd.u[n],"origin")
            if not sd.has_e then
                set sd.has_e = true
            endif
        endif
        call SetUnitVertexColor(sd.u[n],r,g,b,255)
        call SetUnitScale(sd.u[n],scale,scale,scale)

        set n=n+1
        exitwhen n>number
    endloop

    call CheckLoopTimer()
    set TotalSpiral = TotalSpiral + 1
    set sd.id = TotalSpiral
    set SD[TotalSpiral] = sd

 return sd
endfunction

endlibrary

//===========================================================================
function InitTrig_EffectSystem takes nothing returns nothing
endfunction
05-10-2007, 04:15 AM#2
Vexorian
It means you are calling .destroy() on the same object twice.
05-10-2007, 05:14 AM#3
MysticGeneral
Since when does JASS allow structs to be made?
05-10-2007, 05:16 AM#4
Pyrogasm
Since vJASS...
05-10-2007, 05:39 AM#5
MysticGeneral
What's vJASS? Lol.
05-10-2007, 07:54 AM#6
MaD[Lion]
go to warcraft editing tools and download jass new gen pack. This will give u so much power over noobish jass
05-10-2007, 11:23 AM#7
zen87
mmmm weird, i've look into my code few times and i still cant see the part where i called .destroy() twice on the same struct @.@
05-10-2007, 01:28 PM#8
Vexorian
Well don't expect to find a line with

Collapse JASS:
    s.destroy()
    s.destroy()

That won't happen unless you are really weird at coding, if you would actually tell us the name of the library and struct type it would be easier to tractk, but either way if it is double free of type xlibrary_foo then something you could do is add different debug messages before every place you call destroy on an object of that type and see the one called before that warning appears.


The error itself is not a big deal, it just protected you from a double free, when you compile it in non-debug mode the warning will not appear. But it is a sign of a coding mistake, that could probably cause other issues, the same part that is double freeing that thing could be doing other wrong stuff.
05-10-2007, 02:47 PM#9
zen87
ahhh ! thanks !! I've finally found my mistake, I forget to change the sd.id to the new id when i moved the last struct to the destryoing struct !!

all was fixed when i replaced the DestroySpiralEffect with this

Collapse JASS:
function DestroySpiralEffect takes SpiralData sd returns nothing
    if sd.id != TotalSpiral then
        set SD[sd.id] = SD[TotalSpiral] //
        set SD[TotalSpiral].id = sd.id  //moving last data to this data
debug call BJDebugMsg("moving spiral of "+I2S(TotalSpiral)+" to "+I2S(sd.id))
    endif
debug call BJDebugMsg("have a total spiral of "+I2S(TotalSpiral))
    set TotalSpiral = TotalSpiral - 1
    loop
        if sd.has_e then
            call DestroyEffect(sd.e[sd.n])
        endif
        call RecycleCaster(sd.u[sd.n])
        set sd.n = sd.n - 1
        exitwhen sd.n < 1
    endloop
    call sd.destroy()
endfunction

many mnay thanks !! +rep