I've managed to create a wrapper class based on the Bullet Demos (mainly the "Hello World" demo from Bullet, as it is fairly simple, didn't have to search for code in a lot of files).
Everything worked fine, the application had output in text form. I thought the class was "Working" and was good for improvement. But right after I passed from text output to glut, the program crashed on the line "m_World->stepSimulation(timeStep,maxSubSteps);" (timeStep=1/60; maxSubSteps=10).
The "Step into" option of the debugger took me to line 201 from btCollisionObject.h ("return m_internalType;")
Code: Select all
///reserved for Bullet internal usage
int getInternalType() const
{
return m_internalType;
}
That simulation steps once, but the second time it has to step I get this exception.Unhandled exception at 0x00430d46 in physics.exe: 0xC0000005: Access violation reading location 0xfeeeffba.
here's the code executed when the body is added to the simulation (before the exception is thrown)
Code: Select all
//create a dynamic rigidbody
/*01*/ btCollisionShape* colShape = new btSphereShape(Radius);
/*02*/ colShape->setUserPointer(new PS_Sphere(Radius));
/*03*/ m_CollisionShapes.push_back(colShape);
/// Create Dynamic Objects
/*04*/ btTransform startTransform;
/*05*/ startTransform.setIdentity();
/*06*/ btScalar mass(1.f);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
/*07*/ bool isDynamic = (mass != 0.f);
/*08*/ btVector3 localInertia(0,0,0);
/*09*/ if (isDynamic)
/*10*/ colShape->calculateLocalInertia(mass,localInertia);
/*11*/ startTransform.setOrigin(btVector3(2,10,0));
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
/*12*/ btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
/*13*/ btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);
/*14*/ btRigidBody* body = new btRigidBody(rbInfo);
/*15*/ m_World->addRigidBody(body);
and the class members:
Code: Select all
btAlignedObjectArray<btCollisionShape*> m_CollisionShapes;
btDiscreteDynamicsWorld* m_World;
btSequentialImpulseConstraintSolver* m_Solver;
btAxisSweep3* m_OverlappingPairCache;
btCollisionDispatcher* m_Dispatcher;
btDefaultCollisionConfiguration* m_CollisionConfiguration;
Code: Select all
Physics::Physics(btVector3 gravity)
{
///collision configuration contains default setup for memory, collision setup. Advanced users can create their own configuration.
m_CollisionConfiguration = new btDefaultCollisionConfiguration();
///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
m_Dispatcher = new btCollisionDispatcher(m_CollisionConfiguration);
///the maximum size of the collision world. Make sure objects stay within these boundaries
///Don't make the world AABB size too large, it will harm simulation quality and performance
btVector3 worldAabbMin(-10000,-10000,-10000);
btVector3 worldAabbMax(10000,10000,10000);
int maxProxies = 1024;
m_OverlappingPairCache = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
m_Solver = new btSequentialImpulseConstraintSolver;
m_World = new btDiscreteDynamicsWorld(m_Dispatcher,m_OverlappingPairCache,m_Solver,m_CollisionConfiguration);
m_World->setGravity(gravity);
}
Why would this exception be thrown?