HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

[!]Handle Pointers get reset

07-31-2004, 03:49 PM#1
danny760311
I bet somebody would like to store values of a handle (unit, trig, etc) by gamecache with return bug. But I found that it's unsafe.

For example, if unit A's pointer is 12345678. When it dies, it will be removed when its corpse faded. Then 12345678 refers to nothing. But when a new object is created, it will use the empty pointer number again. So maybe a new-created unit(or trig, timer, location, or whatever) will have the pointer 12345678.

And as a result, if you store some value, and uses the unit's pointer as the key. When you use the same way to load the value of unit B, you'll load unit A's, not empty value. :<

It's unsafe isn't it? Does someone have an idea to solve this problem?
07-31-2004, 04:04 PM#2
Vexorian
remove the refference when the unit dies
08-01-2004, 12:13 AM#3
danny760311
Quote:
Originally Posted by Lord Vexorian
remove the refference when the unit dies

I don't think it always work, for example, what if the unit can be revived??
08-01-2004, 10:30 PM#4
Extrarius
Quote:
Originally Posted by danny760311
I don't think it always work, for example, what if the unit can be revived??
It is possible to set the amount of time corpses stay, so you could do something like:

Set corpse stay to 75 seconds

On Unit Death:
Wait 70 Seconds
If Unit Still Dead - then - remove corpse, reset cache data

That way you get 70 seconds of corpse stay with the corpse removed and the data removed at the same time. If the unit comes back, no big deal because it handles that. The only thing it DOESNT handle would be if the unit comes alive again and then dies again after 69 seconds, it would be removed instantly. This can be fixed, but it is more complicated than I care to explain
08-02-2004, 04:10 PM#5
Cubasis
Quote:
it will use the empty pointer number again.

Are you sure that it reuses pointers. I think it just keeps going upwards untill it comes up to a limit, where the emergency garbage collection thingy kicks off, and then it starts reusing old pointers.

But if this is really a concern, you can use this quick fix that should work:

Code:
function ReferenceHandle takes handle h returns nothing
   local handle ref = h
endfunction

If you call this function with a handle, it "should" never be re-used, if our theories are correct. But please note that this is only a concern if you're a vivid leak-fighter and allways null your local handles.

~Cubasis
08-02-2004, 04:48 PM#6
Aiursrage2k
The likely hood of it happening is low. If you worry then put controlls in the situation to make it more managable.
08-03-2004, 09:23 PM#7
Vexorian
For units, you can just wait till their maximum life is 0
08-04-2004, 10:36 AM#8
danny760311
Quote:
Originally Posted by Cubasis
Are you sure that it reuses pointers. I think it just keeps going upwards untill it comes up to a limit, where the emergency garbage collection thingy kicks off, and then it starts reusing old pointers.

But if this is really a concern, you can use this quick fix that should work:

Yes I am sure. You can test for yourself.

Quote:
Code:
function ReferenceHandle takes handle h returns nothing
   local handle ref = h
endfunction

If you call this function with a handle, it "should" never be re-used, if our theories are correct. But please note that this is only a concern if you're a vivid leak-fighter and allways null your local handles.

~Cubasis
Why?
08-04-2004, 08:29 PM#9
Vexorian
Quote:
Originally Posted by danny760311
Yes I am sure. You can test for yourself.


Why?
Because since locals that aren't set to null leak, that will also make sure the handle never derrefferences in theory