I am new to Bullet and came across a little problem with destroying instances of btDiscreteDynamicsWorld. If I add a rigid body to a btDiscreteDynamicsWorld and then try to delete it, I get the following error:
If I just remove the rigid bodies before deleting it, I don't get an error. The following minimal code demonstrates the problem. Maybe you can tell me what I am doing wrong.pure virtual method called
terminate called without an active exception
Aborted (core dumped)
Code: Select all
#include "btBulletDynamicsCommon.h"
int main(int argc, char* argv[]) {
btCollisionConfiguration* collisionCfg = new btDefaultCollisionConfiguration;
btDiscreteDynamicsWorld* world = new btDiscreteDynamicsWorld(
new btCollisionDispatcher(collisionCfg),
new btAxisSweep3(
btVector3(-100, -100, -100),
btVector3(100, 100, 100),
128),
new btSequentialImpulseConstraintSolver,
collisionCfg);
btTransform transform;
btRigidBody* body = new btRigidBody(
1.0,
new btDefaultMotionState(transform),
new btBoxShape(btVector3(2, 2, 2)),
btVector3(10.0, 10.0, 10.0));
world->addRigidBody(body);
delete world->getDispatcher();
delete world->getBroadphase();
delete world->getConstraintSolver();
delete world; // results in an error
delete body->getMotionState();
delete body->getCollisionShape();
delete body;
return 0;
}