I am currently trying to implement the Bullet physics into my game project. However, when i add some rigid bodies to the scene, i occasionally get an error in btDbvtBroadphase.cpp at the line
if(proxy->stage==STAGECOUNT) (line 294).

If i then inspect the proxy pointer, it points to 0x0. If I go back to the function btCollisionWorld::updateSingleAabb(btCollisionObject * colObj) on the call stack, and inspect the member m_broadphaseHandle, it is non-zero, which is being passed as first parameter to btDbvtBroadphase::setAabb(btBroadphaseProxy* absproxy, const btVector3& aabbMin, const btVector3& aabbMax, btDispatcher* __ formal).
In this method it is being cast into a btDbvtProxy pointer and stored in proxy. What I don't get here is, why proxy becomes 0x0, even though a valid pointer is being passed to the function.

The call stack looks like this:

MyProject.exe!btDbvtBroadphase::setAabb(btBroadphaseProxy * absproxy, const btVector3 & aabbMin, const btVector3 & aabbMax, btDispatcher * __formal) Line 294   C++
MyProject.exe!btCollisionWorld::updateSingleAabb(btCollisionObject * colObj) Line 171   C++
MyProject.exe!btCollisionWorld::updateAabbs() Line 204  C++
MyProject.exe!btCollisionWorld::performDiscreteCollisionDetection() Line 220    C++
MyProject.exe!btDiscreteDynamicsWorld::internalSingleStepSimulation(float timeStep) Line 492    C++
MyProject.exe!btDiscreteDynamicsWorld::stepSimulation(float timeStep, int maxSubSteps, float fixedTimeStep) Line 452    C++

The initialization of bullet looks like this:

broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;

world = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
world->setGravity(btVector3(0.0f, -10.0f, 0.0f));

I create RigidBodies procedurally and this is, how I add them:

bp.mesh = new btTriangleMesh(true, false);

for (int i = 0; i < bp.numFaces; ++i)
    btVector3 a(vertices[indices[i * 3 + 0]].position.x, vertices[indices[i * 3 + 0]].position.y, vertices[indices[i * 3 + 0]].position.z);
    btVector3 b(vertices[indices[i * 3 + 1]].position.x, vertices[indices[i * 3 + 1]].position.y, vertices[indices[i * 3 + 1]].position.z);
    btVector3 c(vertices[indices[i * 3 + 2]].position.x, vertices[indices[i * 3 + 2]].position.y, vertices[indices[i * 3 + 2]].position.z);
    bp.mesh->addTriangle(a, b, c);

btMotionState* ms = new btDefaultMotionState;
btBvhTriangleMeshShape* shape = new btBvhTriangleMeshShape(bp.mesh, true);

sect->rigidBody = new btRigidBody(0.0f, ms, shape);

btWorld->addRigidBody(sect->rigidBody, 64, 128);

My question now is, why proxy occasionally points to 0x0, even though it should be a valid pointer? I downloaded and successfully compiled bullet-2.82-r2704 with VS2012 and changed the project settings from /MT(d) to /MD(d), if this does matter.

Edit: I may also mention that the rigid bodies are added in a different thread, than the thread in which I initialize and simulate the bullet physics. Can this cause any problems?

| improve this question | | | | |

It seems that it was in fact, caused by adding rigid bodies from different threads. After I moved the call to btDynamicsWorld::addRigidBody into the main thread, I did not receive this error again.

| improve this answer | | | | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.