Entity exists?

BlitzMax Forums/MiniB3D Module/Entity exists?

ima747(Posted 2007) [#1]
Is there any way to tell if an entity exists? When you free an entity it doesn't null it's pointer, according to the documentation. I assume that's because you can have numerous pointers to the same entity, which makes sense, but raises the problem that if you free an entity, and you access it from multiple points, how can you tell that you can no longer access it? as trying to access a freed entity causes the program to crash...


H&K(Posted 2007) [#2]
Well, generaly you should know if the entity is still being used. There was quite a long theard by either Gab or GFK, about being able to find out how many referances an object still had, and flame gave a "Hack" that allowed you to find out.
But I think the basic rule came down to
1) Count the refences yourself.
2) It shouldnt matter. (But there was quite a split about this, and I for one changed my mind hlafway though it. Either search for the thread, or hopfully someone who remembers it will post a link)


ima747(Posted 2007) [#3]
Will do. I agree that keeping track of it yourself is probably the best idea however it relates to the sound module I've been working on. When someone free's an entity it would be nice if the sound module could find out if the entity is gone and stop the sounds it's playing without the user having to stop the sounds before freeing the entity. Since I use the entity to figure out the positional stuff for the sound, if I try to update a sound attached to a freed entity it crashes the program. Good coding can prevent it, but I, being an idiot, like things to be more idiot proof if possible :0)

I haven't played around with hooks before but I think I could hook the freeentity command to also stop the sounds... but that adds code to every call to freeentity, and I only need to stop sounds if the entity is playing them... which my current system can handle in it's update routine just fine, if it could find out if the entity exists or not...

I'll dig around on the forums some more.


H&K(Posted 2007) [#4]
It was Gabriel, dont know how relevent it is. And the Hack was by Dream

http://www.blitzmax.com/Community/posts.php?topic=62724#705151


ima747(Posted 2007) [#5]
Thanks for the link.

I think what I want is actualy simpler than the topic of the thread, unless I'm not understanding it properly.

For my purposes I don't care how many references to an entity there are. I just need to know if the entity exists or not. By my understanding if I creat a sphere, and then create another handle to that sphere, I have 2 references to the same object. if I call FreeEntity() on either handle it will remove the sphere, but I will have 2 handles pointing to some random spot in memory where the sphere used to be. What I need to be able to do is find out, through either of those handles, if the sphere itself has been freed or not...

untested example would look something like this.

mySphere = CreateSphere(8) ' make a sphere
anotherWayToLookAtMySphere = mySphere ' get an extra handle to the sphere

FreeEntity(mySphere) ' kills the sphere in the 3D world

' if I try to MoveEntity(mySphere) or MoveEntity(anotherWayToLookAtMySphere) the program will crash because the sphere entity no longer exists...