Memory leaks

smittix
Posts: 3
Joined: Mon Oct 27, 2008 5:25 pm

Memory leaks

Post by smittix »

I'm attempting to incorporate Bullet into my game, but getting a memory leak using Visual Studio 2005 just by creating and destroying the basic objects. After playing with it for a while I realized that the memory leaks are coming from calling "new btSequentialImpulseConstraintSolver" and "new btDiscreteDynamicsWorld". Below are the memory leaks I'm getting:

Detected memory leaks!
Dumping objects ->
{437} normal block at 0x00B7E550, 32 bytes long.
Data: <\ L o ; > 5C 91 4C 00 01 00 00 00 6F 12 03 3B 06 00 00 00
{436} normal block at 0x00B7D700, 32 bytes long.
Data: <t L ; > 74 91 4C 00 01 00 00 00 A6 9B C4 3B 04 00 00 00
{129} normal block at 0x00B76B80, 32 bytes long.
Data: < 6 qV > 99 9E 36 00 00 00 00 00 B5 71 56 01 CD CD CD CD
Object dump complete.

The following is the only physics-related code being run:

Code: Select all

PhysicsManager::PhysicsManager(void) : Singleton<PhysicsManager>(ThePhysicsManager)
{
	///collision configuration contains default setup for memory, collision setup
	m_collisionConfiguration = new btDefaultCollisionConfiguration();
	//m_collisionConfiguration->setConvexConvexMultipointIterations();

	///use the default collision dispatcher. For parallel processing you can use a diffent dispatcher (see Extras/BulletMultiThreaded)
	m_dispatcher = new	btCollisionDispatcher(m_collisionConfiguration);

	m_broadphase = new btDbvtBroadphase();

	///the default constraint solver. For parallel processing you can use a different solver (see Extras/BulletMultiThreaded)
	btSequentialImpulseConstraintSolver* sol = new btSequentialImpulseConstraintSolver;
	m_solver = sol;

	m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_broadphase,m_solver,m_collisionConfiguration);

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

PhysicsManager::~PhysicsManager(void)
{
	//cleanup in the reverse order of creation/initialization

	//remove the rigidbodies from the dynamics world and delete them
	int i;
	for (i=m_dynamicsWorld->getNumCollisionObjects()-1; i>=0 ;i--)
	{
		btCollisionObject* obj = m_dynamicsWorld->getCollisionObjectArray()[i];
		btRigidBody* body = btRigidBody::upcast(obj);
		if (body && body->getMotionState())
		{
			delete body->getMotionState();
		}
		m_dynamicsWorld->removeCollisionObject( obj );
		delete obj;
	}

	delete m_dynamicsWorld;
	delete m_solver;
	delete m_broadphase;
	delete m_dispatcher;
	delete m_collisionConfiguration;
}
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: Memory leaks

Post by lulzfish »

Do you get them immediately, or after the main loop exits?
smittix
Posts: 3
Joined: Mon Oct 27, 2008 5:25 pm

Re: Memory leaks

Post by smittix »

I call _CrtDumpMemoryLeaks() at the very end of my WinMain function, right before "return uMsg.wParam;". I would assume all physics objects would be destroyed by that point, no?
lulzfish
Posts: 43
Joined: Mon Jan 03, 2011 4:26 pm

Re: Memory leaks

Post by lulzfish »

I wonder if you shouldn't be calling btDiscreteDynamicsWorld::removeRigidBody() instead of removeCollisionObject?