More example code is memory-leak free now, in particular PhysicsServerExample.

/PhysicsServerCommandProcessor
also fixed some memory issue in InverseDynamicsExample (the base class is supposed to delete collision shape memory)
This commit is contained in:
Erwin Coumans
2016-07-16 21:29:31 -07:00
parent 589fa376b3
commit c54a61b97a
9 changed files with 104 additions and 18 deletions

View File

@@ -21,6 +21,7 @@ void GraphingTexture::destroy()
m_height=0;
glDeleteTextures(1,(GLuint*)&m_textureId);
m_textureId=0;
}
bool GraphingTexture::create(int texWidth, int texHeight)

View File

@@ -675,7 +675,10 @@ struct QuickCanvas : public Common2dCanvasInterface
virtual void destroyCanvas(int canvasId)
{
btAssert(canvasId>=0);
delete m_gt[canvasId];
m_gt[canvasId] = 0;
destroyTextureWindow(m_gw[canvasId]);
m_gw[canvasId] = 0;
m_curNumGraphWindows--;
}
virtual void setPixel(int canvasId, int x, int y, unsigned char red, unsigned char green,unsigned char blue, unsigned char alpha)
@@ -745,6 +748,7 @@ OpenGLExampleBrowser::~OpenGLExampleBrowser()
delete m_internalData;
gFileImporterByExtension.clear();
gAllExamples = 0;
}

View File

@@ -15,7 +15,7 @@
#include "../Importers/ImportURDFDemo/ImportURDFSetup.h"
#include "../Importers/ImportSDFDemo/ImportSDFSetup.h"
#include "../Importers/ImportSTLDemo/ImportSTLSetup.h"
#include "LinearMath/btAlignedAllocator.h"
int main(int argc, char* argv[])
@@ -49,5 +49,11 @@ int main(int argc, char* argv[])
delete exampleBrowser;
}
//#ifdef BT_DEBUG_MEMORY_ALLOCATIONS
int numBytesLeaked = btDumpMemoryLeaks();
btAssert(numBytesLeaked==0);
//#endif//BT_DEBUG_MEMORY_ALLOCATIONS
return 0;
}

View File

@@ -73,7 +73,6 @@ class InverseDynamicsExample : public CommonMultiBodyBase
{
btInverseDynamicsExampleOptions m_option;
btMultiBody* m_multiBody;
btAlignedObjectArray<btCollisionShape*> m_allocatedShapes;
btInverseDynamics::MultiBodyTree *m_inverseModel;
TimeSeriesCanvas* m_timeSeriesCanvas;
public:
@@ -107,12 +106,6 @@ InverseDynamicsExample::InverseDynamicsExample(struct GUIHelperInterface* helper
InverseDynamicsExample::~InverseDynamicsExample()
{
delete m_multiBody;
for (int i = 0; i < m_allocatedShapes.size(); i++)
{
delete m_allocatedShapes[i];
}
m_allocatedShapes.resize(0);
delete m_inverseModel;
delete m_timeSeriesCanvas;
}
@@ -175,7 +168,7 @@ void InverseDynamicsExample::initPhysics()
ConvertURDF2Bullet(u2b,creation, identityTrans,m_dynamicsWorld,true,u2b.getPathPrefix());
for (int i = 0; i < u2b.getNumAllocatedCollisionShapes(); i++)
{
m_allocatedShapes.push_back(u2b.getAllocatedCollisionShape(i));
m_collisionShapes.push_back(u2b.getAllocatedCollisionShape(i));
}
m_multiBody = creation.getBulletMultiBody();
if (m_multiBody)

View File

@@ -31,6 +31,10 @@ struct UrdfLinkNameMapUtil
UrdfLinkNameMapUtil():m_mb(0),m_memSerializer(0)
{
}
virtual ~UrdfLinkNameMapUtil()
{
delete m_memSerializer;
}
};

View File

@@ -78,7 +78,6 @@ PhysicsServerSharedMemory::PhysicsServerSharedMemory(SharedMemoryInterface* shar
}
m_data->m_commandProcessor = new PhysicsServerCommandProcessor;
m_data->m_commandProcessor ->createEmptyDynamicsWorld();
}

View File

@@ -701,7 +701,16 @@ void TinyRendererVisualShapeConverter::copyCameraImageData(unsigned char* pixels
void TinyRendererVisualShapeConverter::resetAll()
{
//todo: free memory
for (int i=0;i<m_data->m_swRenderInstances.size();i++)
{
TinyRendererObjectArray** ptrptr = m_data->m_swRenderInstances.getAtIndex(i);
if (ptrptr && *ptrptr)
{
TinyRendererObjectArray* ptr = *ptrptr;
delete ptr;
}
}
m_data->m_swRenderInstances.clear();
}