Crash on initialization

Luther
Posts: 4
Joined: Thu May 20, 2010 10:53 pm

Crash on initialization

Post by Luther »

Hi All,
I'm currently converting my project from ODE to bullet. I managed to get everything linked and compiled but suffered a run-time crash at a very early stage and I'm unsure what to do.
Here's a code snipit:

Code: Select all

void CScene::init_physics()
{
     m_broadphase = new btDbvtBroadphase();
     // Set up the collision configuration and dispatcher
     m_collisionConfiguration = new btDefaultCollisionConfiguration();
     m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
     // The actual physics solver
     m_solver = new btSequentialImpulseConstraintSolver();
     // The world.
     m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
}
So far, so simple. It's just copied from the hello world app.
However, I get the following error on trying to construct the btDiscreteDynamicsWorld object:

Unhandled exception at 0x77f2fbae in ClayWorksD.exe: Microsoft C++ exception: std::bad_alloc at memory location 0x0012ead4..

I've tried to fiddle with the bullet project settings so that they're in line with the rest of the project. I've tried dynamic and static linking and I get the same error.
I've put breakpoints in the constructor but it barfs in the new.

Has anybody else had a similar sort of error?

Cheers,
Luther.
Luther
Posts: 4
Joined: Thu May 20, 2010 10:53 pm

Re: Crash on initialization

Post by Luther »

Looking at it closer, it seems it only crashes after creating 'btSequentialImpulseConstraintSolver' which contains some (16 byte) aligned objects. Could my problem be due to alignment issues?

Anything allocated after that object get constructed seems to die a death.

Cheers,
Luther.
Luther
Posts: 4
Joined: Thu May 20, 2010 10:53 pm

Re: Crash on initialization

Post by Luther »

I've been bashing this problem all night and no success. The demos build and run fine so I've tried copying all the project settings from those and applying them to my own project. No luck, it still crashes. I've tried moving the initialization code around to see if I'm stomping over the memory somewhere. No joy, it still crashes. It either crashes when creating the physics scene or with any subsequent allocation calls.

My app works fine without any calls to bullet.

Has anybody ever seen anything like this before?

My guess is this is an order of construction problem so I'm making sure I don't have any complex globals doing anything before the app has started. If I find the answer, I'll post it here so that other might avoid the same mistake. I'm not sure if anybody is reading this, you're a quiet bunch :D

Thanks.
Luther
Posts: 4
Joined: Thu May 20, 2010 10:53 pm

Re: Crash on initialization

Post by Luther »

Turns out that some of my code had a #pragma pack(1) call to ensure the correct alignment of a struct. What it didn't have was a #pragma pack(push) and #pragma pack(pop) surrounding it so this messed up Bullet's alignment. Hopefully this will help somebody else avoid the same problem.