• 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] VJass: 'Double free of type: mystruct' / Destruction of a custom array type

Status
Not open for further replies.
Level 3
Joined
Sep 11, 2008
Messages
58
Once more i have an understanding-problem with vjass, thus i'd be glad if someone of the more advanced VJassers could give me a hint.

I have a struct (mystruct) with 3 variables. A type (mytype) extends an array of this struct with a size of 10.

In a method of another struct i'm using this type locally, creating it (mytype myarray = mytype.create()) within that method and then creating multiple members for it (e.g. myarray[1].create(x, y)). At the end of the method i call another method to destroy the members (e.g. myarray[1].destroy()) and then the array itself (myarray.destroy())... and i get the message 'Double free of type: mystruct'.

Below the method where i destroy them:

JASS:
static method destroy_myarray takes mytype myarray returns nothing
    local integer i
    set i = 0
    loop
        exitwhen i > mytype.size - 1
        if not (myarray[i] == 0) then
            call myarray[i].destroy()
        endif
        set i = i + 1
    endloop
    call myarray.destroy()
endmethod

What i thought i do: free the x instances of mystruct and then free the 10 array indices of mytype. But concerning the message i got, i now assume, that myarray.destroy() also frees the instances of mystruct. And indeed, when i remove myarray.destroy() from the method i don't get that message anymore. But i'm not sure if the previously assigned 10 indices of mytype are really free to use again then. If i instead only call myarray.destroy(), without destroying the instances of mystruct, i neither get the message. But it leads to different results. In the first case the method where i use myarray in works, in the other it doesn't. I'm quite clueless...

Thanks for any help
whisp
 
Last edited:
Level 14
Joined
Nov 18, 2007
Messages
816
JASS:
struct myothertype
    integer bar
endstruct

struct mytype
    myothertype array othertypearray[10]
    
    method onDestroy takes nothing returns nothing
    local integer i=0
        loop
            exitwhen i>=10
            call this.othertypearray[i].destroy()
            set i=i+1
        endloop
    endmethod
    
endstruct

So, instead of calling destroy_myarray(mytypeinstance), you call mytypeinstance.destroy()
 
Level 3
Joined
Sep 11, 2008
Messages
58
Thanks for your answers...

Sorry disciple, i confused some of the placeholders (mytype instead of myarray and more). I fixed it in my first post.

I can try it your way, Deaod, and declare the array as an instance variable only, instead of creating a dynamic array type before. Sounds like this would fix my problem, but it will make it a bit more complicated, since i'm also using it as a local array within methods (and thus have to destroy the array-indexes separately within that method).
 
Status
Not open for further replies.
Top