fix potential memory leaks for concave triangle meshes (<concave=true> or createCollisionShape with flags=1)
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -78,6 +78,9 @@ public:
|
||||
virtual int getNumModels() const;
|
||||
virtual void activateModel(int modelIndex);
|
||||
|
||||
virtual int getNumAllocatedMeshInterfaces() const;
|
||||
virtual btStridingMeshInterface* getAllocatedMeshInterface(int index);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -54,6 +54,7 @@ ATTRIBUTE_ALIGNED16(struct) BulletURDFInternalData
|
||||
int m_bodyId;
|
||||
btHashMap<btHashInt,UrdfMaterialColor> m_linkColors;
|
||||
btAlignedObjectArray<btCollisionShape*> m_allocatedCollisionShapes;
|
||||
mutable btAlignedObjectArray<btTriangleMesh*> m_allocatedMeshInterfaces;
|
||||
|
||||
LinkVisualShapesConverter* m_customVisualShapesConverter;
|
||||
|
||||
@@ -572,7 +573,7 @@ bool findExistingMeshFile(
|
||||
}
|
||||
}
|
||||
|
||||
btCollisionShape* convertURDFToCollisionShape(const UrdfCollision* collision, const char* urdfPathPrefix)
|
||||
btCollisionShape* BulletURDFImporter::convertURDFToCollisionShape(const UrdfCollision* collision, const char* urdfPathPrefix) const
|
||||
{
|
||||
BT_PROFILE("convertURDFToCollisionShape");
|
||||
|
||||
@@ -775,6 +776,7 @@ upAxisMat.setIdentity();
|
||||
{
|
||||
BT_PROFILE("convert trimesh");
|
||||
btTriangleMesh* meshInterface = new btTriangleMesh();
|
||||
m_data->m_allocatedMeshInterfaces.push_back(meshInterface);
|
||||
{
|
||||
BT_PROFILE("convert vertices");
|
||||
|
||||
@@ -1229,6 +1231,19 @@ btCollisionShape* BulletURDFImporter::getAllocatedCollisionShape(int index)
|
||||
return m_data->m_allocatedCollisionShapes[index];
|
||||
}
|
||||
|
||||
int BulletURDFImporter::getNumAllocatedMeshInterfaces() const
|
||||
{
|
||||
return m_data->m_allocatedMeshInterfaces.size();
|
||||
}
|
||||
|
||||
|
||||
btStridingMeshInterface* BulletURDFImporter::getAllocatedMeshInterface(int index)
|
||||
{
|
||||
return m_data->m_allocatedMeshInterfaces[index];
|
||||
}
|
||||
|
||||
|
||||
|
||||
class btCompoundShape* BulletURDFImporter::convertLinkCollisionShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const
|
||||
{
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ public:
|
||||
|
||||
virtual void convertLinkVisualShapes2(int linkIndex, int urdfIndex, const char* pathPrefix, const btTransform& inertialFrame, class btCollisionObject* colObj, int bodyUniqueId) const;
|
||||
|
||||
class btCollisionShape* convertURDFToCollisionShape(const struct UrdfCollision* collision, const char* urdfPathPrefix) const;
|
||||
|
||||
///todo(erwincoumans) refactor this convertLinkCollisionShapes/memory allocation
|
||||
|
||||
virtual class btCompoundShape* convertLinkCollisionShapes(int linkIndex, const char* pathPrefix, const btTransform& localInertiaFrame) const;
|
||||
@@ -69,7 +71,9 @@ public:
|
||||
virtual int getNumAllocatedCollisionShapes() const;
|
||||
virtual class btCollisionShape* getAllocatedCollisionShape(int index);
|
||||
|
||||
|
||||
virtual int getNumAllocatedMeshInterfaces() const;
|
||||
virtual class btStridingMeshInterface* getAllocatedMeshInterface(int index);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -80,6 +80,8 @@ public:
|
||||
virtual class btCollisionShape* getAllocatedCollisionShape(int /*index*/ ) {return 0;}
|
||||
virtual int getNumModels() const {return 0;}
|
||||
virtual void activateModel(int /*modelIndex*/) { }
|
||||
virtual int getNumAllocatedMeshInterfaces() const { return 0;}
|
||||
virtual class btStridingMeshInterface* getAllocatedMeshInterface(int index) {return 0;}
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user