Topic: when are physics shapes and objects deleted?

I see that MPhysicsContext has deleteShape() and deleteObject() method but I don't see them used anywhere.
If I do

entity->createPhysicsProperties();

physics properties and constraint are SAFE_DELETEd which means

delete pointer;
pointer = NULL;

but the physics shape and object are not deleted.
I then call

scene->prepareCollisionShape(entity);
scene->prepareCollisionObject(entity);

but in these functions there is no deleting of the previous object neither.

Re: when are physics shapes and objects deleted?

shapes and objects are automatically deleted by the physics context clear() function
MBulletContext::clear(void)

clear is called by MBulletContext::init, itself called by MScene::preparePhysics

Re: when are physics shapes and objects deleted?

This is "preparing", "initializing", but I'm talking about deleting an entity or its physics properties. The actual physics objects and shapes are NOT deleted.
I was just guessing, reading the source code, but now I've done a test and it's actually a real bug.

Create a project, create a falling box and a plane with mass 0.00 to stop the falling box.
In your game plugin do

MOEntity* plane = scene->getEntityByName("Plane");
scene->deleteObject(plane);

Run the game, the box will fall and it will soon be stopped by the invisible physics object left by the plane entity.

Re: when are physics shapes and objects deleted?

Yes, in this case you will need to destroy or at least deactivate the physics object manually just before :

MPhysicsProperties * phyProps = plane->getPhysicsProperties();
if(phyProps)
    physics->deactivateObject(phyProps->getCollisionObjectId());

Re: when are physics shapes and objects deleted?

Still, I consider this not the expected behavior.
If you do a lua function "deleteEntity()" I'm sure you will delete all the associated physics objects, so the same should be with C++.
You can make MScene do this, while the MOEntity code shouldn't need to be touched. I think this would keep a good design/structure.