Question about bullet and jbullet physics space destroy method

Hi,

Is there any reason why the destroy method in PhysicsSpace class clears physicsBodies and physicsJoints but not physicsGhostObjects, physicsCharacters and physicsVehicles? Just curious

/**
 * destroys the current PhysicsSpace so that a new one can be created
 */
public void destroy() {
    physicsBodies.clear();
    physicsJoints.clear();

    dynamicsWorld.destroy();
    dynamicsWorld = null;
}

Thanks

2 Likes

I assume skipping physicsCharacters.clear() was an oversight.

I believe physicsVehicles would be a subset of physicsBodies, so physicsVehicles.clear() would have little effect except to hasten garbage collection. But perhaps hastening garbage collection is the main rationale for destroy(). The rationale isn’t clear to me.

1 Like

I assume skipping physicsCharacters.clear() was an oversight.

so an issue? anyone know?

Not sure about how physics work but from my point of view and because this method is only called once the bulletAppState has been removed from the state manager, it makes sense to clear all of them :thinking:

Also I don’t know if this is may cause any kind of issue in a long term run if the bullet state is removed and then re-added…