- removed warnings in GLUI, thanks Jorrit Tyberghein for the patch!

- removed memory leaks from BasicDemo and Bullet library (other demos needs to be cleaned up!)
- added memory leak debugging functionality in btAlignedAlloc.h: #define BT_DEBUG_MEMORY_ALLOCATIONS
This commit is contained in:
ejcoumans
2007-10-31 08:00:03 +00:00
parent 42fc5b37cc
commit a101719687
15 changed files with 374 additions and 152 deletions

View File

@@ -18,31 +18,93 @@ subject to the following restrictions:
#include "../CcdPhysicsDemo/CcdPhysicsDemo.h"
#include "../BspDemo/BspDemo.h"
#include "../BasicDemo/BasicDemo.h"
#include "../ConcaveDemo/ConcaveDemo.h"
#include "../ConvexDecompositionDemo/ConvexDecompositionDemo.h"
#include "../RagdollDemo/RagdollDemo.h"
#include "../GimpactTestDemo/GimpactTestDemo.h"
#include "../Raytracer/Raytracer.h"
#include "../GjkConvexCastDemo/LinearConvexCastDemo.h"
#include "../VehicleDemo/VehicleDemo.h"
#include "../ConstraintDemo/ConstraintDemo.h"
#include "../ConcaveDemo/ConcaveDemo.h"
#include "../ConvexDecompositionDemo/ConvexDecompositionDemo.h"
#include "../RagdollDemo/RagdollDemo.h"
#include "../GimpactTestDemo/GimpactTestDemo.h"
#include "../Raytracer/Raytracer.h"
#include "../GjkConvexCastDemo/LinearConvexCastDemo.h"
#include "../VehicleDemo/VehicleDemo.h"
#include "../ConstraintDemo/ConstraintDemo.h"
#include "GlutStuff.h"//OpenGL stuff
#include "BMF_Api.h"//font stuff
extern int gNumAlignedAllocs;
extern int gNumAlignedFree;
extern int gTotalBytesAlignedAllocs;
class btEmptyDebugDemo : public DemoApplication
{
public:
btEmptyDebugDemo()
{
}
virtual void clientMoveAndDisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
float xOffset = 10.f;
float yStart = 20.f;
float yIncr = 20.f;
char buf[124];
glColor3f(0, 0, 0);
setOrthographicProjection();
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"gNumAlignedAllocs= %d",gNumAlignedAllocs);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"gNumAlignedFree= %d",gNumAlignedFree);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"# alloc-free = %d",gNumAlignedAllocs-gNumAlignedFree);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"gTotalBytesAlignedAllocs = %d",gTotalBytesAlignedAllocs);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
glFlush();
glutSwapBuffers();
}
static DemoApplication* Create()
{
btEmptyDebugDemo* demo = new btEmptyDebugDemo();
demo->myinit();
return demo;
}
btDemoEntry g_demoEntries[] =
{
{"RagdollDemo",RagdollDemo::Create},
{"ConvexDecomposition",ConvexDecompositionDemo::Create},
{"CcdPhysicsDemo", CcdPhysicsDemo::Create},
{"BasicDemo", BasicDemo::Create},
{"BspDemo", BspDemo::Create},
{"ConcaveDemo",ConcaveDemo::Create},
{"Gimpact Test", GimpactConcaveDemo::Create},
{"Raytracer Test",Raytracer::Create},
{"GjkConvexCast",LinearConvexCastDemo::Create},
{"VehicleDemo",VehicleDemo::Create},
{"ConstraintDemo",ConstraintDemo::Create},
{0, 0}
};
btDemoEntry g_demoEntries[] =
{
{"BasicDemo", BasicDemo::Create},
{"RagdollDemo",RagdollDemo::Create},
{"ConvexDecomposition",ConvexDecompositionDemo::Create},
{"CcdPhysicsDemo", CcdPhysicsDemo::Create},
{"BspDemo", BspDemo::Create},
{"ConcaveDemo",ConcaveDemo::Create},
{"Gimpact Test", GimpactConcaveDemo::Create},
{"Raytracer Test",Raytracer::Create},
{"GjkConvexCast",LinearConvexCastDemo::Create},
{"VehicleDemo",VehicleDemo::Create},
{"ConstraintDemo",ConstraintDemo::Create},
{"MemoryLeakChecker",btEmptyDebugDemo::Create},
{0, 0}
};

View File

@@ -124,7 +124,7 @@ void BasicDemo::initPhysics()
setCameraDistance(btScalar(50.));
btDefaultCollisionConfiguration* collisionConfiguration = new btDefaultCollisionConfiguration();
m_collisionConfiguration = new btDefaultCollisionConfiguration();
#ifdef USE_PARALLEL_DISPATCHER
@@ -147,7 +147,7 @@ void BasicDemo::initPhysics()
m_dispatcher = new SpuGatheringCollisionDispatcher(threadSupport,maxNumOutstandingTasks,collisionConfiguration);
#else
m_dispatcher = new btCollisionDispatcher(collisionConfiguration);
m_dispatcher = new btCollisionDispatcher(m_collisionConfiguration);
#endif //USE_PARALLEL_DISPATCHER
#define USE_SWEEP_AND_PRUNE 1
@@ -172,9 +172,9 @@ void BasicDemo::initPhysics()
#ifdef USE_SIMPLE_DYNAMICS_WORLD
//btSimpleDynamicsWorld doesn't support 'cache friendly' optimization, so disable this
sol->setSolverMode(btSequentialImpulseConstraintSolver::SOLVER_RANDMIZE_ORDER);
m_dynamicsWorld = new btSimpleDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,collisionConfiguration);
m_dynamicsWorld = new btSimpleDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,m_collisionConfiguration);
#else
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,collisionConfiguration);
m_dynamicsWorld = new btDiscreteDynamicsWorld(m_dispatcher,m_overlappingPairCache,m_solver,m_collisionConfiguration);
#endif //USE_SIMPLE_DYNAMICS_WORLD
m_dynamicsWorld->getDispatchInfo().m_enableSPU = true;
@@ -246,6 +246,11 @@ void BasicDemo::exitPhysics()
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;
}
@@ -269,6 +274,8 @@ void BasicDemo::exitPhysics()
//delete dispatcher
delete m_dispatcher;
delete m_collisionConfiguration;
}

View File

@@ -24,6 +24,7 @@ class btOverlappingPairCache;
class btCollisionDispatcher;
class btConstraintSolver;
struct btCollisionAlgorithmCreateFunc;
class btDefaultCollisionConfiguration;
///BasicDemo is good starting point for learning the code base and porting.
class BasicDemo : public DemoApplication
@@ -42,8 +43,17 @@ class BasicDemo : public DemoApplication
btCollisionAlgorithmCreateFunc* m_sphereBoxCF;
btCollisionAlgorithmCreateFunc* m_boxSphereCF;
btDefaultCollisionConfiguration* m_collisionConfiguration;
public:
BasicDemo()
{
}
virtual ~BasicDemo()
{
exitPhysics();
}
void initPhysics();
void exitPhysics();

View File

@@ -116,39 +116,7 @@ int shapeIndex[maxNumObjects];
// btPoint3(50,0,0));
static const int numShapes = 4;
btCollisionShape* shapePtr[numShapes] =
{
///Please don't make the box sizes larger then 1000: the collision detection will be inaccurate.
///See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=346
//#define USE_GROUND_PLANE 1
#ifdef USE_GROUND_PLANE
new btStaticPlaneShape(btVector3(0,1,0),0.5),
#else
new btBoxShape (btVector3(200,CUBE_HALF_EXTENTS,200)),
#endif
#ifdef DO_BENCHMARK_PYRAMIDS
new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)),
#else
new btCylinderShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS)),
#endif
//new btSphereShape (CUBE_HALF_EXTENTS),
//new btCapsuleShape(0.5*CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS),
//new btCylinderShape (btVector3(1-gCollisionMargin,CUBE_HALF_EXTENTS-gCollisionMargin,1-gCollisionMargin)),
//new btConeShapeX(CUBE_HALF_EXTENTS,2.f*CUBE_HALF_EXTENTS),
new btSphereShape (CUBE_HALF_EXTENTS),
//new btBU_Simplex1to4(btPoint3(-1,-1,-1),btPoint3(1,-1,-1),btPoint3(-1,1,-1),btPoint3(0,0,1)),
//new btEmptyShape(),
new btBoxShape (btVector3(0.4,1,0.8))
};
btCollisionShape* shapePtr[numShapes] = {0,0,0,0};
void CcdPhysicsDemo::createStack( btCollisionShape* boxShape, float halfCubeSize, int size, float zPos )
{
@@ -363,6 +331,39 @@ float myFrictionModel( btRigidBody& body1, btRigidBody& body2, btManifoldPoint&
void CcdPhysicsDemo::initPhysics()
{
shapePtr[0] =
///Please don't make the box sizes larger then 1000: the collision detection will be inaccurate.
///See http://www.continuousphysics.com/Bullet/phpBB2/viewtopic.php?t=346
//#define USE_GROUND_PLANE 1
#ifdef USE_GROUND_PLANE
new btStaticPlaneShape(btVector3(0,1,0),0.5);
#else
new btBoxShape (btVector3(200,CUBE_HALF_EXTENTS,200));
#endif
shapePtr[1] =
#ifdef DO_BENCHMARK_PYRAMIDS
new btBoxShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS));
#else
new btCylinderShape (btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS));
#endif
shapePtr[2] =
//new btSphereShape (CUBE_HALF_EXTENTS);
//new btCapsuleShape(0.5*CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS);
//new btCylinderShape (btVector3(1-gCollisionMargin,CUBE_HALF_EXTENTS-gCollisionMargin,1-gCollisionMargin));
//new btConeShapeX(CUBE_HALF_EXTENTS,2.f*CUBE_HALF_EXTENTS);
new btSphereShape (CUBE_HALF_EXTENTS);
//new btBU_Simplex1to4(btPoint3(-1,-1,-1),btPoint3(1,-1,-1),btPoint3(-1,1,-1),btPoint3(0,0,1));
//new btEmptyShape();
shapePtr[3] = new btBoxShape (btVector3(0.4,1,0.8));
#ifdef DO_BENCHMARK_PYRAMIDS
setCameraDistance(2.5f);
#endif

View File

@@ -43,6 +43,7 @@ extern int gNumDeepPenetrationChecks;
extern int gNumGjkChecks;
extern int gNumAlignedAllocs;
extern int gNumAlignedFree;
extern int gTotalBytesAlignedAllocs;
#endif //
@@ -52,6 +53,7 @@ DemoApplication::DemoApplication()
:
m_dynamicsWorld(0),
m_pickConstraint(0),
m_shootBoxShape(0),
m_cameraDistance(15.0),
m_debugMode(0),
m_ele(20.f),
@@ -75,6 +77,8 @@ m_pickConstraint(0),
DemoApplication::~DemoApplication()
{
if (m_shootBoxShape)
delete m_shootBoxShape;
}
@@ -461,14 +465,19 @@ void DemoApplication::shootBox(const btVector3& destination)
startTransform.setIdentity();
btVector3 camPos = getCameraPosition();
startTransform.setOrigin(camPos);
//#define TEST_UNIFORM_SCALING_SHAPE 1
if (!m_shootBoxShape)
{
//#define TEST_UNIFORM_SCALING_SHAPE 1
#ifdef TEST_UNIFORM_SCALING_SHAPE
btConvexShape* childShape = new btBoxShape(btVector3(1.f,1.f,1.f));
btUniformScalingShape* boxShape = new btUniformScalingShape(childShape,0.5f);
m_shootBoxShape = new btUniformScalingShape(childShape,0.5f);
#else
btCollisionShape* boxShape = new btBoxShape(btVector3(0.5f,0.5f,0.5f));
m_shootBoxShape = new btBoxShape(btVector3(0.5f,0.5f,0.5f));
#endif//
btRigidBody* body = this->localCreateRigidBody(mass, startTransform,boxShape);
}
btRigidBody* body = this->localCreateRigidBody(mass, startTransform,m_shootBoxShape);
btVector3 linVel(destination[0]-camPos[0],destination[1]-camPos[1],destination[2]-camPos[2]);
linVel.normalize();
@@ -701,7 +710,8 @@ btRigidBody* DemoApplication::localCreateRigidBody(float mass, const btTransform
btRigidBody* body = new btRigidBody(mass,myMotionState,shape,localInertia);
#else
btRigidBody* body = new btRigidBody(mass,startTransform,shape,localInertia);
btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);
body->setWorldTransform(startTransform);
#endif//
m_dynamicsWorld->addRigidBody(body);
@@ -923,6 +933,28 @@ void DemoApplication::renderme()
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
//enable BT_DEBUG_MEMORY_ALLOCATIONS define in Bullet/src/LinearMath/btAlignedAllocator.h for memory leak detection
#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"gTotalBytesAlignedAllocs = %d",gTotalBytesAlignedAllocs);
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
#endif //BT_DEBUG_MEMORY_ALLOCATIONS
if (getDynamicsWorld())
{
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"# objects = %d",getDynamicsWorld()->getNumCollisionObjects());
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
glRasterPos3f(xOffset,yStart,0);
sprintf(buf,"# pairs = %d",getDynamicsWorld()->getBroadphase()->getOverlappingPairCache()->getNumOverlappingPairs());
BMF_DrawString(BMF_GetFont(BMF_kHelvetica10),buf);
yStart += yIncr;
}
#endif //SHOW_NUM_DEEP_PENETRATIONS
resetPerspectiveProjection();

View File

@@ -58,6 +58,8 @@ class DemoApplication
///constraint for mouse picking
btTypedConstraint* m_pickConstraint;
btCollisionShape* m_shootBoxShape;
float m_cameraDistance;
int m_debugMode;