HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

UnitUserData/Struct Question

07-30-2007, 08:59 PM#1
Beardo
is there a way to destroy a struct attached via SetUnitUserData() after it dies? I tried

Collapse JASS:
function SomeFunction takes nothing returns nothing
local unit killed             = GetTriggerUnit()
local mobdata mobd         = GetUnitUserData(killed)


call mobd.destroy() //Get rid of the struct

but Grimoire gave me "attempt to destroy null struct of type" error. Any way around this? or am I going to have to use CSData?
07-30-2007, 10:10 PM#2
Vexorian
I don't remember correctly but it looks like killing a unit breaks cleans its userdata? In that case you can try to catch the life becomes 0 event (which is hard to deal without leaks) or use an alternative to UnitUserData
07-30-2007, 10:15 PM#3
Beardo
I thought so

CSdata should work though, right?
07-30-2007, 11:04 PM#4
Vexorian
yes..
07-30-2007, 11:11 PM#5
Beardo
Changed it to CSData. Now I get a double free warning when I try to destroy it

Does CSData automatically clear itself when the unit dies or what?
07-31-2007, 12:31 AM#6
Vexorian
You are most likely doing something wrong, would have to see some code.