Hi,
I'm new to Bullet Physics and getting started with a simple c++ app. I am starting with the tutorial code at: http://bulletphysics.org/mediawiki-1.5. ... pplication
With the full source code in an xcode 4.5 command line app project, on OS X 10.7.5, locally compiled Bullet 2.81, with frameworks LinearMath, BulletCollision, and BulletDynamics, the code compiles successfully, but running the app in Debug mode I get an exception: EXC_BAD_ACCESS (code=13, address=0x0) when executing line:
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
The exception occurs in btMatrix3x3.h
// Assignment Operator
SIMD_FORCE_INLINE btMatrix3x3& operator=(const btMatrix3x3& m)
{
m_el[0].mVec128 = m.m_el[0].mVec128; // <-- exception here
m_el[1].mVec128 = m.m_el[1].mVec128;
m_el[2].mVec128 = m.m_el[2].mVec128;
return *this;
}
I've looked through the xcode project settings and everything looks correct. Any suggestions on how to resolve this exception?
Thanks,
Henry
OS X EXC_BAD_ACCESS error when running Bullet tutoral code
-
- Posts: 2
- Joined: Sun Oct 21, 2012 7:25 am
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: OS X EXC_BAD_ACCESS error when running Bullet tutoral co
Your crash is likely due to unaligned data, since Bullet 2.81 some data needs to be 16-byte aligned.
If you use 'new' to allocated memory it might not be 16-byte aligned.
The wiki is likely out-of-date, it is better to use the sample/demos from the Bullet SDK directly,
for example the Bullet/Demos/HelloWorld source code. Also see Bullet-2.81/docs/BulletQuickstart.pdf
Thanks,
Erwin
If you use 'new' to allocated memory it might not be 16-byte aligned.
The wiki is likely out-of-date, it is better to use the sample/demos from the Bullet SDK directly,
for example the Bullet/Demos/HelloWorld source code. Also see Bullet-2.81/docs/BulletQuickstart.pdf
Thanks,
Erwin
-
- Posts: 2
- Joined: Sun Oct 21, 2012 7:25 am
Re: OS X EXC_BAD_ACCESS error when running Bullet tutoral co
Thanks Erwin, the version in Bullet/Demos/HelloWorld successfully builds and runs.Erwin Coumans wrote:Your crash is likely due to unaligned data, since Bullet 2.81 some data needs to be 16-byte aligned.
If you use 'new' to allocated memory it might not be 16-byte aligned.
The wiki is likely out-of-date, it is better to use the sample/demos from the Bullet SDK directly,
for example the Bullet/Demos/HelloWorld source code. Also see Bullet-2.81/docs/BulletQuickstart.pdf
Henry
-
- Site Admin
- Posts: 4221
- Joined: Sun Jun 26, 2005 6:43 pm
- Location: California, USA
Re: OS X EXC_BAD_ACCESS error when running Bullet tutoral co
By the way, I cannot reproduce the problem. I compiled the code from the wiki and copy and pasted it over the HelloWorld.cpp demo and it just runs fine.
Did you make any modifications? What compiler (and version) do you use, LLVM or GCC?
Did you make any modifications? What compiler (and version) do you use, LLVM or GCC?
Code: Select all
#include <iostream>
#include <btBulletDynamicsCommon.h>
int main (void)
{
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
btCollisionShape* fallShape = new btSphereShape(1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo
groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
btDefaultMotionState* fallMotionState =
new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
btScalar mass = 1;
btVector3 fallInertia(0,0,0);
fallShape->calculateLocalInertia(mass,fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
dynamicsWorld->addRigidBody(fallRigidBody);
for (int i=0 ; i<300 ; i++) {
dynamicsWorld->stepSimulation(1/60.f,10);
btTransform trans;
fallRigidBody->getMotionState()->getWorldTransform(trans);
std::cout << "sphere height: " << trans.getOrigin().getY() << std::endl;
}
dynamicsWorld->removeRigidBody(fallRigidBody);
delete fallRigidBody->getMotionState();
delete fallRigidBody;
dynamicsWorld->removeRigidBody(groundRigidBody);
delete groundRigidBody->getMotionState();
delete groundRigidBody;
delete fallShape;
delete groundShape;
delete dynamicsWorld;
delete solver;
delete collisionConfiguration;
delete dispatcher;
delete broadphase;
return 0;
}
-
- Posts: 5
- Joined: Thu Sep 26, 2013 8:10 pm
Re: OS X EXC_BAD_ACCESS error when running Bullet tutoral co
I am facing the same problem with bullet 2.81
I cannot even run the hello world demo.
Crashes on this point in btVector3.h (line 144)
The code runs OK inside the project created by CMake. But it will not run when I create a new project from inside Xcode and put this code in it, and link the code with the libraries. The xcode project settings seem to be the same as bullet's though.
You mentioned something about 16-bit alignment. Is there any way we can ensure alignment such as this?
Any idea on this? Please help, I have been trying to solve this problem for two days straight.
I cannot even run the hello world demo.
Code: Select all
#include <iostream>
#include <btBulletDynamicsCommon.h>
int main (void)
{
btBroadphaseInterface* broadphase = new btDbvtBroadphase();
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
btDiscreteDynamicsWorld* dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-10,0));
btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),1);
btCollisionShape* fallShape = new btSphereShape(1);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,-1,0)));
btRigidBody::btRigidBodyConstructionInfo
groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
btRigidBody* groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
btDefaultMotionState* fallMotionState =
new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
btScalar mass = 1;
btVector3 fallInertia(0,0,0);
fallShape->calculateLocalInertia(mass,fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,fallShape,fallInertia);
btRigidBody* fallRigidBody = new btRigidBody(fallRigidBodyCI);
dynamicsWorld->addRigidBody(fallRigidBody);
for (int i=0 ; i<300 ; i++) {
dynamicsWorld->stepSimulation(1/60.f,10);
btTransform trans;
fallRigidBody->getMotionState()->getWorldTransform(trans);
std::cout << "sphere height: " << trans.getOrigin().getY() << std::endl;
}
dynamicsWorld->removeRigidBody(fallRigidBody);
delete fallRigidBody->getMotionState();
delete fallRigidBody;
dynamicsWorld->removeRigidBody(groundRigidBody);
delete groundRigidBody->getMotionState();
delete groundRigidBody;
delete fallShape;
delete groundShape;
delete dynamicsWorld;
delete solver;
delete collisionConfiguration;
delete dispatcher;
delete broadphase;
return 0;
}
Crashes on this point in btVector3.h (line 144)
Code: Select all
SIMD_FORCE_INLINE btVector3(const btVector3& rhs)
{
mVec128 = rhs.mVec128; // <--crash here
}
You mentioned something about 16-bit alignment. Is there any way we can ensure alignment such as this?
Any idea on this? Please help, I have been trying to solve this problem for two days straight.
-
- Posts: 4
- Joined: Sun Dec 15, 2013 2:24 pm
Re: OS X EXC_BAD_ACCESS error when running Bullet tutoral co
Hi,
I get the same exception thrown when I exit my app on Win32 VS2010.
Exception occurs in btMatrix3x3.h at line 124 Bullet version 2.82:
Exception message: 0xC0000005: Access violation writing location 0xdddddded.
It does not occur every time though. Sometimes the app exits clean. I will investigate further follow up in this thread.
UPDATE: The cause laid of course in a memory leak when I was fetching vertex data of multiple meshes and sending them to Bullet.
I get the same exception thrown when I exit my app on Win32 VS2010.
Exception occurs in btMatrix3x3.h at line 124 Bullet version 2.82:
Code: Select all
m_el[0] = other.m_el[0];
It does not occur every time though. Sometimes the app exits clean. I will investigate further follow up in this thread.
UPDATE: The cause laid of course in a memory leak when I was fetching vertex data of multiple meshes and sending them to Bullet.