OgreNewt::Collision life times

litghost

16-09-2007 00:56:42

In demo 3, you create conveyor belts with the following code:

// create the collision object for the conveyor belt.
OgreNewt::Collision* col = new OgreNewt::CollisionPrimitives::Box( world, size );
mBody = new OgreNewt::Body( world, col, conveyorType );
delete col;


This seems okay, but you store the collision pointer in OgreNewt::Body, and it can be retrieved later via the getCollision. While you never use the collision pointer after the constructor or the get within the OgreNewt::Body class, is it really a good idea to have OgreNewt::Body have a pointer to a deleted object? Did you mean for OgreNewt::Body to has a copy of the collision pointer? Why doesn't OgreNewt::Body handle the collision pointer?

walaber

16-09-2007 17:56:11

you don't have to delete it, but since Collision objects are reference-counted by Newton, if you don't delete the Collision object, Newton will think you are always using it, and will never delete it. for a larger game, this may be an issue.

the pointer in Body should only be used if you will need it later, and if so, obviously you should not delete the Collision object if you still need it.