Fixed memory leaks in ConvexDecomposition and ColladaConverter libraries

Added ConvexDecompositionDemo to CMake build
This commit is contained in:
john.mccutchan
2008-08-28 17:36:50 +00:00
parent 5fd1a69f32
commit 32bf51aa47
9 changed files with 89 additions and 26 deletions

View File

@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 2.4)
PROJECT(BULLET_PHYSICS) PROJECT(BULLET_PHYSICS)
IF (NOT CMAKE_BUILD_TYPE) IF (NOT CMAKE_BUILD_TYPE)
SET(CMAKE_BUILD_TYPE "Release") SET(CMAKE_BUILD_TYPE "Debug")
ENDIF (NOT CMAKE_BUILD_TYPE) ENDIF (NOT CMAKE_BUILD_TYPE)
@@ -25,6 +25,7 @@ MESSAGE("OPENGL NOT FOUND")
SET(OPENGL_gl_LIBRARY opengl32) SET(OPENGL_gl_LIBRARY opengl32)
SET(OPENGL_glu_LIBRARY glu32) SET(OPENGL_glu_LIBRARY glu32)
ENDIF (OPENGL_FOUND) ENDIF (OPENGL_FOUND)
ADD_DEFINITIONS(-DBT_USE_FREEGLUT)
FIND_PACKAGE(GLU) FIND_PACKAGE(GLU)

View File

@@ -0,0 +1,26 @@
# This is basically the overall name of the project in Visual Studio this is the name of the Solution File
# For every executable you have with a main method you should have an add_executable line below.
# For every add executable line you should list every .cpp and .h file you have associated with that executable.
# This is the variable for Windows. I use this to define the root of my directory structure.
SET(GLUT_ROOT ${BULLET_PHYSICS_SOURCE_DIR}/Glut)
# You shouldn't have to modify anything below this line
########################################################
INCLUDE_DIRECTORIES(
${BULLET_PHYSICS_SOURCE_DIR}/src ${BULLET_PHYSICS_SOURCE_DIR}/Demos/OpenGL ${BULLET_PHYSICS_SOURCE_DIR}/Extras/ConvexDecomposition
)
LINK_LIBRARIES(
LibOpenGLSupport LibBulletDynamics LibBulletCollision LibLinearMath LibConvexDecomposition ${GLUT_glut_LIBRARY} ${OPENGL_gl_LIBRARY} ${OPENGL_glu_LIBRARY}
)
ADD_EXECUTABLE(ConvexDecompositionDemo
main.cpp
ConvexDecompositionDemo.cpp
)

View File

@@ -351,6 +351,8 @@ void ConvexDecompositionDemo::initPhysics(const char* filename)
startTransform.setOrigin(convexDecompositionObjectOffset); startTransform.setOrigin(convexDecompositionObjectOffset);
localCreateRigidBody(0.f,startTransform,concaveShape); localCreateRigidBody(0.f,startTransform,concaveShape);
m_collisionShapes.push_back (concaveShape);
} }

View File

@@ -23,6 +23,10 @@ int main(int argc,char** argv)
return glutmain(argc, argv,640,480,"Bullet Physics Demo. http://www.continuousphysics.com/Bullet/phpBB2/",convexDecompDemo); glutmain(argc, argv,640,480,"Bullet Physics Demo. http://www.continuousphysics.com/Bullet/phpBB2/",convexDecompDemo);
delete convexDecompDemo;
return 0;
} }

View File

@@ -176,6 +176,19 @@ ColladaConverter::~ColladaConverter ()
m_collada = NULL; m_collada = NULL;
m_dom = NULL; m_dom = NULL;
for(int i=0;i<m_rbUserInfoHashMap.size();i++)
{
btRigidBodyColladaInfo* rbci = *(m_rbUserInfoHashMap.getAtIndex(i));
delete rbci;
}
for(int i=0;i<m_constraintUserInfoHashMap.size();i++)
{
btRigidConstraintColladaInfo* rcci = *(m_constraintUserInfoHashMap.getAtIndex(i));
delete rcci;
}
} }
@@ -226,6 +239,18 @@ bool ColladaConverter::load(const char* orgfilename)
// resets the collada converter state // resets the collada converter state
void ColladaConverter::reset () void ColladaConverter::reset ()
{ {
for(int i=0;i<m_rbUserInfoHashMap.size();i++)
{
btRigidBodyColladaInfo* rbci = *(m_rbUserInfoHashMap.getAtIndex(i));
delete rbci;
}
for(int i=0;i<m_constraintUserInfoHashMap.size();i++)
{
btRigidConstraintColladaInfo* rcci = *(m_constraintUserInfoHashMap.getAtIndex(i));
delete rcci;
}
// clear the maps // clear the maps
m_rbUserInfoHashMap.clear (); m_rbUserInfoHashMap.clear ();
m_constraintUserInfoHashMap.clear (); m_constraintUserInfoHashMap.clear ();
@@ -2808,27 +2833,24 @@ void ColladaConverter::ConvertRigidBodyRef( btRigidBodyInput& rbInput,btRigidBod
} }
} }
if (rbOutput.m_isDynamics)
{
printf("moving concave <mesh> not supported, transformed into convex\n");
rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
} else
{
printf("static concave triangle <mesh> added\n");
bool useQuantizedAabbCompression = true;
rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh,useQuantizedAabbCompression);
//rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
//rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
//btTriangleMeshShape
}
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
} }
if (rbOutput.m_isDynamics)
{
printf("moving concave <mesh> not supported, transformed into convex\n");
rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
} else
{
printf("static concave triangle <mesh> added\n");
bool useQuantizedAabbCompression = true;
rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh,useQuantizedAabbCompression);
//rbOutput.m_colShape = new btBvhTriangleMeshShape(trimesh);
//rbOutput.m_colShape = new btConvexTriangleMeshShape(trimesh);
//btTriangleMeshShape
}
//rbOutput.m_colShape->setTypedUserInfo (new btShapeColladaInfo (geom));
} else } else
{ {

View File

@@ -150,7 +150,10 @@ CHull * ConvexBuilder::canMerge(CHull *a,CHull *b)
//don't do anything if hull is empty //don't do anything if hull is empty
if (!tcount) if (!tcount)
{
Vl_releaseVertexLookup (vc);
return 0; return 0;
}
HullResult hresult; HullResult hresult;
HullLibrary hl; HullLibrary hl;
@@ -323,6 +326,8 @@ unsigned int ConvexBuilder::process(const DecompDesc &desc)
mCallback->ConvexDecompResult(r); mCallback->ConvexDecompResult(r);
} }
hl.ReleaseResult (result);
delete cr; delete cr;
} }

View File

@@ -204,6 +204,7 @@ void calcConvexDecomposition(unsigned int vcount,
} }
#endif #endif
hl.ReleaseResult (result);
return; return;
} }

View File

@@ -816,8 +816,8 @@ WavefrontObj::WavefrontObj(void)
WavefrontObj::~WavefrontObj(void) WavefrontObj::~WavefrontObj(void)
{ {
delete mIndices; delete [] mIndices;
delete mVertices; delete [] mVertices;
} }
unsigned int WavefrontObj::loadObj(const char *fname) // load a wavefront obj returns number of triangles that were loaded. Data is persists until the class is destructed. unsigned int WavefrontObj::loadObj(const char *fname) // load a wavefront obj returns number of triangles that were loaded. Data is persists until the class is destructed.
@@ -825,9 +825,9 @@ unsigned int WavefrontObj::loadObj(const char *fname) // load a wavefront obj re
unsigned int ret = 0; unsigned int ret = 0;
delete mVertices; delete [] mVertices;
mVertices = 0; mVertices = 0;
delete mIndices; delete [] mIndices;
mIndices = 0; mIndices = 0;
mVertexCount = 0; mVertexCount = 0;
mTriCount = 0; mTriCount = 0;

View File

@@ -97,6 +97,8 @@ btSoftBody::~btSoftBody()
delete m_collisionShape; delete m_collisionShape;
int i; int i;
for(i=0;i<m_clusters.size();++i)
btAlignedFree(m_clusters[i]);
for(i=0;i<m_materials.size();++i) for(i=0;i<m_materials.size();++i)
btAlignedFree(m_materials[i]); btAlignedFree(m_materials[i]);
for(i=0;i<m_joints.size();++i) for(i=0;i<m_joints.size();++i)