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:
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
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: