SimObject::deleteObject() fails
by Juan Aramburu · in Torque Game Engine Advanced · 06/06/2006 (8:13 pm) · 1 replies
When I call shape.deleteObject() [shape is a TSStatic], TSE crashes when it executes "delete this":
However, if I don't call shape.deleteObject(), I get an assert:
The object is a child class of WheeledVehicle, and onRemove() has these statements:
But of course deleteObject() crashes TSE. What is the problem?
Note: everything runs fine in the release mode (if I comment out the deleteObject(), but am probably leaking memory/resources).
void SimObject::deleteObject()
{
AssertFatal(mFlags.test(Added),
"SimObject::deleteObject: Object not registered.");
AssertFatal(!isDeleted(),"SimManager::deleteObject: "
"Object has already been deleted");
AssertFatal(!isRemoved(),"SimManager::deleteObject: "
"Object in the process of being removed");
mFlags.set(Deleted);
unregisterObject();
delete this;
}However, if I don't call shape.deleteObject(), I get an assert:
SimObject::object missing call to SimObject::onRemove
The object is a child class of WheeledVehicle, and onRemove() has these statements:
void SimChild2::onRemove()
{
shape.removeFromScene();
shape.deleteObject();
Parent::onRemove();
}But of course deleteObject() crashes TSE. What is the problem?
Note: everything runs fine in the release mode (if I comment out the deleteObject(), but am probably leaking memory/resources).
Torque Owner Juan Aramburu
TSStatic shape;
when it should have been
TSStatic* shape;
The "delete this" statement made the light bulb go on.