Runtime error when deleting dynamicsWorld...

colinhect
Posts: 3
Joined: Mon Jan 18, 2010 6:33 pm

Runtime error when deleting dynamicsWorld...

Post by colinhect »

I'm writing a simple wrapping class around bullet to integrate into my game. It currently just sets up bullet and then cleans up after it (like in the Hello World app).

Here is the source:

Code: Select all

class bullet_physics_simulator : public physics_simulator {

public:

	bullet_physics_simulator();
	~bullet_physics_simulator();

private:

	btAxisSweep3* broadphase;
	btDefaultCollisionConfiguration* collision_config;
	btCollisionDispatcher* dispatcher;
	btSequentialImpulseConstraintSolver* solver;
	btDiscreteDynamicsWorld* dynamics_world;

};


bullet_physics_simulator::bullet_physics_simulator() {
	broadphase = new btAxisSweep3(btVector3(-1000, -1000, -1000), btVector3(1000, 1000, 1000), 1024);

	collision_config = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collision_config);
 
    solver = new btSequentialImpulseConstraintSolver;
 
    dynamics_world = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collision_config);

	dynamics_world->setGravity(btVector3(0,-10,0));
}

bullet_physics_simulator::~bullet_physics_simulator() {
	delete dynamics_world;
	delete solver;
	delete dispatcher;
	delete collision_config;
	delete broadphase;
}
On the line that deletes dynamics_world the program crashes. I'm compiling with MSVC++ 2010. When debugging it points to the last line on this function in dbgheap.c

Code: Select all

extern "C" _CRTIMP int __cdecl _CrtIsValidHeapPointer(
        const void * pUserData
        )
{
        if (!pUserData)
            return FALSE;

        if (!_CrtIsValidPointer(pHdr(pUserData), sizeof(_CrtMemBlockHeader), FALSE))
            return FALSE;

        return HeapValidate( _crtheap, 0, pHdr(pUserData) ); // Here
}
Any help would be appreciated.
mako90
Posts: 28
Joined: Tue Jan 05, 2010 12:41 pm

Re: Runtime error when deleting dynamicsWorld...

Post by mako90 »

Hi,
why isn't your destructor virtual?

BR.
colinhect
Posts: 3
Joined: Mon Jan 18, 2010 6:33 pm

Re: Runtime error when deleting dynamicsWorld...

Post by colinhect »

Must have slipped my mind. Appreciate the reply, but I'm still running into problems.

I also tried adding a rigid body (using identical code as in the Hello World source) and I similar get runtime errors. The Hello World app compiled and runs fine on my computer. Are there any build options I am missing? I'm also linking with GL, GLU, GLEW, and SDL if that changes anything.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Runtime error when deleting dynamicsWorld...

Post by Erwin Coumans »

Have you tried to just include all the Bullet/src files to your project, and not link against the pre-compiled Bullet libraries?

Thanks,
Erwin
dakffyd
Posts: 13
Joined: Wed Jan 20, 2010 1:35 am

Re: Runtime error when deleting dynamicsWorld...

Post by dakffyd »

I have a similar problem. I'm integrating Bullet into a game engine, and getting run-time errors on initialization.

What I have is essentially identical to all examples I have seen, but when I run bulletinit(), the constructor crashes on the line:
dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration);

Code: Select all

class BulletPhysicsWorld {
private:	
	int lastupdate;

	btConstraintSolver *m_constraintSolver;
	btCollisionDispatcher *m_dispatcher;
	btBroadphaseInterface* m_overlappingPairCache;
	btDefaultCollisionConfiguration *m_collisionConfiguration;
	btAlignedObjectArray<btCollisionShape*> m_collisionShapes;
	btDynamicsWorld*	dynamicsWorld;

public:
	BulletPhysicsWorld();
	virtual ~BulletPhysicsWorld();
};

BulletPhysicsWorld::BulletPhysicsWorld(){
	btVector3 worldMin(-1000,-1000,-1000);
	btVector3 worldMax(1000,1000,1000);

	m_constraintSolver = new btSequentialImpulseConstraintSolver();
	m_overlappingPairCache = new btAxisSweep3(worldMin,worldMax, 1024);
	m_collisionConfiguration = new btDefaultCollisionConfiguration();
	m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
	dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_constraintSolver,m_collisionConfiguration);
}

BulletPhysicsWorld::~BulletPhysicsWorld(){
	delete m_constraintSolver;
	delete m_dispatcher;
	delete m_overlappingPairCache;
	delete m_collisionConfiguration;
	delete dynamicsWorld;
}

void bulletinit(){
	BulletPhysicsWorld *bworld = new BulletPhysicsWorld();
}
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Runtime error when deleting dynamicsWorld...

Post by Erwin Coumans »

dakffyd wrote:I have a similar problem. I'm integrating Bullet into a game engine, and getting run-time errors on initialization.
You might be linking against Bullet libraries that use different settings than your own project. As I mentioned previous, can you please include the Bullet/src files directly in your project, instead of linking against the Bullet precompiled libraries?

Hope this helps,
Thanks,
Erwin
dakffyd
Posts: 13
Joined: Wed Jan 20, 2010 1:35 am

Re: Runtime error when deleting dynamicsWorld...

Post by dakffyd »

Erwin Coumans wrote:
dakffyd wrote:I have a similar problem. I'm integrating Bullet into a game engine, and getting run-time errors on initialization.
You might be linking against Bullet libraries that use different settings than your own project. As I mentioned previous, can you please include the Bullet/src files directly in your project, instead of linking against the Bullet precompiled libraries?

Hope this helps,
Thanks,
Erwin
thanks!

I've added the bullet/src file to my "additional include directories" in visual studio, and included "bullet/src/btBulletDynamicsCommon.h" in my code, but I'm getting 22 unresolved externals. Did I miss something?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Runtime error when deleting dynamicsWorld...

Post by Erwin Coumans »

Add all the .cpp files from Bullet/src in your project, recursively.

XCode can do this automatically, for Visual Studio, simply drag all *.cpp from those folders into your project:

src\LinearMath
src\BulletCollision\BroadphaseCollision
src\BulletCollision\CollisionDispatch
src\BulletCollision\CollisionShapes
src\BulletCollision\Gimpact
src\BulletCollision\NarrowPhaseCollision
src\BulletDynamics\Character
src\BulletDynamics\ConstraintSolver
src\BulletDynamics\Dynamics
src\BulletDynamics\Vehicle
src\BulletSoftBody

Thanks,
Erwin
dakffyd
Posts: 13
Joined: Wed Jan 20, 2010 1:35 am

Re: Runtime error when deleting dynamicsWorld...

Post by dakffyd »

Thanks, that worked!

In order to get it to compile I had to replace

#include <vectormath_aos.h>
with
#include "BulletMultiThreaded/vectormath/scalar/cpp/vectormath_aos.h"'

in two places.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Runtime error when deleting dynamicsWorld...

Post by Erwin Coumans »

dakffyd wrote:Thanks, that worked!

In order to get it to compile I had to replace

#include <vectormath_aos.h>
with
#include "BulletMultiThreaded/vectormath/scalar/cpp/vectormath_aos.h"'

in two places.
Good. This is fixed for upcoming Bullet 2.76, no need to replace those includes.

Thanks!
Erwin