This is my first post on this forum but I have been struggling with Bullet a couple of weeks total. I used it about a year ago and I was impressed by it.
So I thought I should give it a try and implement it in my current game.
Now to the problem. It can be some compiler settings that I haven't set correct or it could be my lack of knowledge in Bullet that causes this but sometimes when I compile my very basic program which creates some rigid bodies that either fall to the ground or are hinged together I get a crash in
btSequentialImpulseConstraintSolver::resolveSingleConstraintRowGenericSIMD()
and more specifically on this row:
__m128 deltaImpulse = _mm_sub_ps(_mm_set1_ps(c.m_rhs), _mm_mul_ps(_mm_set1_ps(c.m_appliedImpulse),_mm_set1_ps(c.m_cfm)));
It happens as soon as I step the world if I have created a btHeightfieldTerrainShape or I have created too many objects (5 of them)...
I initialise my world like this:
Code: Select all
mBroadPhase = OGRE_NEW_T(bt32BitAxisSweep3, Ogre::MEMCATEGORY_GENERAL)(worldMin, worldMax);
// collision configuration and dispatcher
mCollisionConfiguration = OGRE_NEW_T(btDefaultCollisionConfiguration, Ogre::MEMCATEGORY_GENERAL);
mCollisionDispatcher = OGRE_NEW_T(btCollisionDispatcher, Ogre::MEMCATEGORY_GENERAL)(mCollisionConfiguration);
// create the solver
mSolver = OGRE_NEW_T(btSequentialImpulseConstraintSolver, Ogre::MEMCATEGORY_GENERAL);
// finally create the world
mWorld = OGRE_NEW_T(btDiscreteDynamicsWorld, Ogre::MEMCATEGORY_GENERAL)(mCollisionDispatcher, mBroadPhase, mSolver, mCollisionConfiguration);
mWorld->setGravity(btVector3(0, -9.82, 0));Code: Select all
Girder *girder = pm->createGirder(Ogre::Vector3(3, 5, 3), Ogre::Vector3(3, 5, 6), 0.3, NULL);
girder = pm->createGirder(Ogre::Vector3(3, 5, 6), Ogre::Vector3(3, 5, 9), 0.3, girder);
girder = pm->createGirder(Ogre::Vector3(3, 5, 9), Ogre::Vector3(3, 5, 12), 0.3, girder);
Code: Select all
Girder::Girder(Ogre::Vector3 start, Ogre::Vector3 end, Ogre::Real thickness, Ogre::SceneManager *mgr, Girder *anchor1, Girder *anchor2)
{
mGirderID = mNextGirderID++;
mNode = mgr->getRootSceneNode()->createChildSceneNode();
Ogre::Real length = (end - start).length();
mCollisionShape = OGRE_NEW_T(btBoxShape, Ogre::MEMCATEGORY_GENERAL)(btVector3(thickness / 2, thickness / 2, length / 2));
btVector3 localInertia(0, 0, 0);
Ogre::Real mass = 10;
Ogre::Real restitution = 0.6;
Ogre::Real friction = 0.6;
mCollisionShape->calculateLocalInertia(mass, localInertia);
// Ogre::Quaternion ori = (Ogre::Vector3::NEGATIVE_UNIT_Z).getRotationTo(end - start);
btTransform trans;
trans.setIdentity();//.setRotation(btQuaternion(ori.x, ori.y, ori.z, ori.w));//
trans.setOrigin(btVector3((end.x + start.x) / 2, (end.y + start.y) / 2, (end.z + start.z) / 2));
mStartPos = start;
mStartOri = Ogre::Quaternion::IDENTITY;
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
mMotionState = OGRE_NEW_T(GirderMotionState, Ogre::MEMCATEGORY_GENERAL)(trans, mNode);
btRigidBody::btRigidBodyConstructionInfo cInfo(mass, mMotionState, mCollisionShape, localInertia);
mBody = OGRE_NEW_T(btRigidBody, Ogre::MEMCATEGORY_GENERAL)(cInfo);
mBody->setContactProcessingThreshold(BT_LARGE_FLOAT);
mBody->setWorldTransform(trans);
mBody->setRestitution(restitution);
mBody->setFriction(friction);
PhysicsManager::getSingleton().getWorld()->addRigidBody(mBody);
Ogre::Vector3 pivot(0, 0, length / 2);
Ogre::Quaternion ori = (Ogre::Vector3::NEGATIVE_UNIT_Z).getRotationTo((end - start));
pivot = ori * pivot;
btVector3 pivotInA(pivot.x, pivot.y, pivot.z);
btVector3 axisInA(1, 0, 0);
if (anchor1 != NULL)
{
btVector3 pivotInB = anchor1->mBody->getCenterOfMassTransform().inverse()(mBody->getCenterOfMassTransform()(pivotInA));
btVector3 axisInB(anchor1->mBody->getCenterOfMassTransform().getBasis().inverse()*(anchor1->mBody->getCenterOfMassTransform().getBasis() * axisInA));
mConstraint = OGRE_NEW_T(btHingeConstraint, Ogre::MEMCATEGORY_GENERAL)(*mBody, *anchor1->mBody, pivotInA, pivotInB, axisInA, axisInB);
}
else
mConstraint = OGRE_NEW_T(btHingeConstraint, Ogre::MEMCATEGORY_GENERAL)(*mBody, pivotInA, axisInA);
// mConstraint = NULL;
if (mConstraint != NULL)
{
mConstraint->setDbgDrawSize(btScalar(1.f));
PhysicsManager::getSingleton().getWorld()->addConstraint(mConstraint);
}Code: Select all
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-5,0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
mWorld->addRigidBody(groundRigidBody);
Code: Select all
girder = pm->createGirder(Ogre::Vector3(3, 5, 12), Ogre::Vector3(3, 5, 15), 0.3, girder);Code: Select all
const std::vector<float> heights = mTerrainInfo->getHeightmapData();
mTerrainHeights = OGRE_ALLOC_T(float, heights.size(), Ogre::MEMCATEGORY_GENERAL);
/* memcpy(mTerrainHeights, &heights[0], heights.size());
*/
for (size_t i = 0; i < heights.size(); i++)
mTerrainHeights[i] = 0.0f;
btHeightfieldTerrainShape *heightshape = OGRE_NEW_T(btHeightfieldTerrainShape, Ogre::MEMCATEGORY_GENERAL)(mTerrainInfo->getWidth(), mTerrainInfo->getHeight(), (void*)/*&mTerrainInfo->getHeightmapData()[0]*/mTerrainHeights, 1.0f, 1, true, false);
heightshape->setUseDiamondSubdivision(false);
btVector3 scale(TILESIZE / (VERTICES_PER_TILESIDE - 1), (WORLD_HEIGHT - OCEAN_FLOOR_HEIGHT), TILESIZE / (VERTICES_PER_TILESIDE - 1));
heightshape->setLocalScaling(scale);
mWorldCollisionShape = heightshape;
if (mWorldCollisionShape == NULL)
return;
btVector3 minAabb, maxAabb;
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(0, 0, 0));
mWorldCollisionShape->getAabb(trans, minAabb, maxAabb);
trans.setOrigin(btVector3(-minAabb.x(), -minAabb.y() + OCEAN_FLOOR_HEIGHT, -minAabb.z()));
btDefaultMotionState* myMotionState = new btDefaultMotionState(trans);
btRigidBody::btRigidBodyConstructionInfo cInfo(0, myMotionState, mWorldCollisionShape);
// mWorld->addCollisionObject(mWorldCollisionShape);
mWorldBody = OGRE_NEW_T(btRigidBody, Ogre::MEMCATEGORY_GENERAL)(cInfo);
mWorld->debugDrawObject(trans, mWorldCollisionShape, btVector3(1.0f, 0.0f, 1.0f));
mWorldBody->setRestitution(0.1f);
mWorldBody->setFriction(0.8f);
mWorld->addRigidBody(mWorldBody);(I have intentionally set all values to 0.0f for debug purposes...)
Please help me figure out what is wrong here.
Many thanks!