Game Development Community

Asset clearing upon delete problems

by Ronald J Nelson · in Torque 3D Professional · 12/26/2012 (9:23 pm) · 5 replies

I'm having a problem with clearing resources and am hoping someone could help me.

Essentially what I have is a class that has been derived from the physicsShape class. It in turn creates another such object as part of an array that is attached to the core shape.

When I try to delete the object in the world editor or via script using anything other than safeDeleteObject(), the thing crashes for EngineObject::destroySelf().

It is my understanding that clearing objects via script is normally done with safeDeleteObject().

On the other hand, if I use anything other than deleteObject() I cannot exit the game without a crash for any function call that would work if the object was still present because even though the object has been deleted, it apparently wants to process more ticks.

So riddle me this Batman, what can I do to make it work both ways? Thanks in advance.

#1
12/27/2012 (1:06 am)
class SimObjectDeleteEvent : public SimEvent
{
public:
   void process(SimObject *object)
   {
      object->deleteObject();
   }
};

void SimObject::safeDeleteObject()
{
   Sim::postEvent( this, new SimObjectDeleteEvent, Sim::getCurrentTime() + 1 );
}

Looks like it just does a well timed delete.

Did you remember to add these:
DECLARE_CONOBJECT( PhysicsShape ); // in the h file
IMPLEMENT_CO_NETOBJECT_V1(PhysicsShape); // in the cpp file

Of course replace PhysicsShape with your class name of the new object.
#2
12/27/2012 (3:19 am)
Make sure you call Parent::onRemove()?
#3
12/27/2012 (4:46 pm)
Thanks guys, it was pretty much a botched job of abstracting my classes.
#4
12/28/2012 (1:33 am)
Is it simple enough to share the issue and solution? That way if we run into this later there might be an answer.
#5
12/28/2012 (7:55 am)
Well in this case it was a matter of using one abstracted object to represent two possible types. One would require a rendered shape, the other would not, but both would require the mechanics of the object.

As I've learned, it is better to just create two classes in this case, because the object that does not require a rendered shape is still trying to process as if it is rendering.

Frankly the code structure got over complicated and was doomed to have a glitch.