fix potential memory leaks for concave triangle meshes (<concave=true> or createCollisionShape with flags=1)

This commit is contained in:
Erwin Coumans
2017-08-24 09:16:11 -07:00
parent f0c32b84c0
commit 5c5993edcb
6 changed files with 53 additions and 4 deletions

View File

@@ -187,6 +187,7 @@ struct BulletMJCFImporterInternalData
//those collision shapes are deleted by caller (todo: make sure this happens!)
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
mutable btAlignedObjectArray<btTriangleMesh*> m_allocatedMeshInterfaces;
BulletMJCFImporterInternalData()
:m_activeModel(-1),
@@ -1855,6 +1856,8 @@ class btCompoundShape* BulletMJCFImporter::convertLinkCollisionShapes( int linkI
{
btTriangleMesh* meshInterface = new btTriangleMesh();
m_data->m_allocatedMeshInterfaces.push_back(meshInterface);
for (int i=0;i<glmesh->m_numIndices/3;i++)
{
float* v0 = glmesh->m_vertices->at(glmesh->m_indices->at(i*3)).xyzw;
@@ -1926,6 +1929,15 @@ class btCollisionShape* BulletMJCFImporter::getAllocatedCollisionShape(int index
return m_data->m_allocatedCollisionShapes[index];
}
int BulletMJCFImporter::getNumAllocatedMeshInterfaces() const
{
return m_data->m_allocatedMeshInterfaces.size();
}
btStridingMeshInterface* BulletMJCFImporter::getAllocatedMeshInterface(int index)
{
return m_data->m_allocatedMeshInterfaces[index];
}
int BulletMJCFImporter::getNumModels() const
{

View File

@@ -78,6 +78,9 @@ public:
virtual int getNumModels() const;
virtual void activateModel(int modelIndex);
virtual int getNumAllocatedMeshInterfaces() const;
virtual btStridingMeshInterface* getAllocatedMeshInterface(int index);
};