Registering/Unregistering Torque Objects
by Alex Okafor · in Torque X 3D · 02/17/2007 (3:34 pm) · 2 replies
I get an assertion failed when un-registering and re-registering an object. It removes itself successfully from the torque object database but it's objectID is not reset to 0.
this is what I have written for an object that is a simple subclass of T2DSceneObject
the assertion is in TorqueObjectDatabase.cs line 277. So am I missing something about how objects are registered with the DB? It seems like I shouldn't have to reset the object ID and calling Unregister should do the work. Is this a bug?
this is what I have written for an object that is a simple subclass of T2DSceneObject
if (this.IsRegistered)
{
TorqueObjectDatabase.Instance.Unregister(this); // remove so we can register a new component.
}
GSMoveComponent mover = new GSMoveComponent();
this.Components.AddComponent(mover);
TorqueObjectDatabase.Instance.Register(this);the assertion is in TorqueObjectDatabase.cs line 277. So am I missing something about how objects are registered with the DB? It seems like I shouldn't have to reset the object ID and calling Unregister should do the work. Is this a bug?
#2
It's failing in Register in this if statement:
I altered my code to test it out again and it still fails
And setting the Pool to true in my constructor gives me a different error: 'Torque Object is removed but not reset', which is in TorqueObject.cs line 509. adding a .Reset() call before registering doesn't fix this problem either since the Unregistered isn't set to false.
02/18/2007 (10:51 am)
The call to Unregister did return true. It was that the ID of the object didn't seem to be reset to 0.It's failing in Register in this if statement:
if (obj == null || obj.ObjectId != 0 || obj.IsRegistered)
{
Assert.Fatal(false, "Registering an object which is already registered");
return false;
}I altered my code to test it out again and it still fails
if (this.IsRegistered)
{
bool worked = TorqueObjectDatabase.Instance.Unregister(this);
if (worked)
{
TorqueObjectDatabase.Instance.Register(this);
}
}And setting the Pool to true in my constructor gives me a different error: 'Torque Object is removed but not reset', which is in TorqueObject.cs line 509. adding a .Reset() call before registering doesn't fix this problem either since the Unregistered isn't set to false.
Torque Owner Ben R Vesco
I recommend using the debugger to step in to TorqueObjectDatabase.Unregister to find the exact point of failure.