here, i tried to make a miniature project which displays this crashing behaviour.
right now i'm using 2.73, however, with 2.74 earlier i was getting the same kinds of errors.
Code: Select all
// linker options
#pragma comment(linker, "/NODEFAULTLIB:LIBCMTD")
#pragma comment(lib, "libbulletcollision_d.lib")
#pragma comment(lib, "libbulletdynamics_d.lib")
#pragma comment(lib, "libbulletmath_d.lib")
// includes
#include <btBulletCollisionCommon.h>
#include <btBulletDynamicsCommon.h>
#include <iostream>
#include <list>
using namespace std;
btDiscreteDynamicsWorld *World;
// represents a hypothetical game object
class thing
{
public:
btRigidBody* RigidBody;
thing(btVector3 TPosition)
{
// Set the initial position of the object
btTransform Transform;
Transform.setIdentity();
Transform.setOrigin(TPosition);
btDefaultMotionState *MotionState = new btDefaultMotionState(Transform);
// Create the shape
btVector3 HalfExtents(5.0f,5.0f,5.0f);
btCollisionShape *Shape = new btBoxShape(HalfExtents);
// Add mass
btVector3 LocalInertia;
Shape->calculateLocalInertia(10.0f, LocalInertia);
// Create the rigid body object
RigidBody = new btRigidBody(10.0f, MotionState, Shape, LocalInertia);
// Add it to the world
World->addRigidBody(RigidBody);
}
};
// ******
list<thing*> things;
int main() {
cout << "Bullet Physics Library SDK Version " << btGetVersion() << "\n";
// Initialize bullet
btDefaultCollisionConfiguration *CollisionConfiguration = new btDefaultCollisionConfiguration();
btBroadphaseInterface *BroadPhase = new btAxisSweep3(btVector3(-1000, -1000, -1000), btVector3(1000, 1000, 1000));
btCollisionDispatcher *Dispatcher = new btCollisionDispatcher(CollisionConfiguration);
btSequentialImpulseConstraintSolver *Solver = new btSequentialImpulseConstraintSolver();
World = new btDiscreteDynamicsWorld(Dispatcher, BroadPhase, Solver, CollisionConfiguration);
// add some objects
cout << "* adding objects..\n";
int NumObjects = 50;
for(int i=0;i<NumObjects;i++)
{
thing* t = new thing(btVector3(0,20.0f * i,0));
things.push_back(t);
}
// step the world a bit
cout << "* stepping";
for(int i =0;i<200;i++)
{
cout << ".";
World->stepSimulation(1.0f/60.0f, 10);
}
cout << "done.\n* cleaning up";
// clean up
for(list<thing*>::iterator it=things.begin();it!=things.end();++it)
{
cout << ".";
thing* t = *it;
World->removeRigidBody(t->RigidBody);
delete t->RigidBody->getMotionState();
delete t->RigidBody->getCollisionShape();
delete t->RigidBody;
}
delete World;
delete Solver;
delete Dispatcher;
delete BroadPhase;
delete CollisionConfiguration;
cout << "\ndone.";
// done
return 0;
}
some notes:
besides the #pragmas at the top, i haven't changed any of the default settings in a new empty project in VS.
it only crashes after i've created a certain amount of objects, i didn't check the count now except that setting NumObjects to 1 doesn't crash, and 50 does crash.
it crashes in different ways depending on whether i compile as debug (linking with debug libs, as in the code above) or with release (with release libs).
in debug mode, everything seems to work (for once) except for deleting objects in the cleanup iterator, where it crashes with:
Code: Select all
HEAP[btest.exe]: Heap block at 00037CD8 modified at 00037EE3 past requested size of 203
on line 31 of btAlignedAllocator.cpp.
deleting the MotionState works but when i try to delete the RigidBody, i get it.
in release mode, it crashes differently depending on if i use a list, a vector, or nothing to store the "thing" instances.
with a
list, it crashes on line 93 (m_collisionObjects.push_back(... ) in btCollisionWorld.cpp with:
Code: Select all
First-chance exception at 0x7c902c53 in btest.exe: 0xC0000005: Access violation writing location 0x00037000.
First-chance exception at 0x00429826 in btest.exe: 0xC0000005: Access violation writing location 0x00000004.
Unhandled exception at 0x00429826 in btest.exe: 0xC0000005: Access violation writing location 0x00000004.
with a
vector, it points to line 177 of btDbvtBroadphase.cpp (proxy->stage = m_stageCurrent) with:
Code: Select all
First-chance exception at 0x7c902c53 in btest.exe: 0xC0000005: Access violation writing location 0x007f5000.
First-chance exception at 0x0040fc5b in btest.exe: 0xC0000005: Access violation writing location 0x0000003c.
Unhandled exception at 0x0040fc5b in btest.exe: 0xC0000005: Access violation writing location 0x0000003c.
without storing the references, just creating a bunch of class instances, it points to line 454 of btDiscreteDynamicsWorld.cpp with:
Code: Select all
HEAP[btest.exe]: Heap missing last entry in committed range near 372a8
am i just creating/storing my RigidBody references in an incorrect way? the messages seem to indicate that, but i'm not exactly an expert..
here's some lines from the call stack tab after one of the crashes:
Code: Select all
> btest.exe!btDiscreteDynamicsWorld::addRigidBody(btRigidBody * body=0x000372c0) Line 454 + 0xb bytes C++
btest.exe!thing::thing(btVector3 TPosition={...}) Line 45 C++
btest.exe!main() Line 68 + 0x63 bytes C++
btest.exe!___CxxFrameHandler3() + 0xec bytes C++
btest.exe!__SEH_epilog4() + 0x13 bytes Asm
kernel32.dll!7c839ac0()