From ed5a4e195b1e4bb55c89444eaa5546d3dd5edc35 Mon Sep 17 00:00:00 2001 From: elsid Date: Sat, 30 Oct 2021 03:38:38 +0200 Subject: [PATCH] Use unique_ptr to avoid possible memory leak --- components/resource/bulletshapemanager.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/resource/bulletshapemanager.cpp b/components/resource/bulletshapemanager.cpp index ae6f3659a5..39ceb4fe7e 100644 --- a/components/resource/bulletshapemanager.cpp +++ b/components/resource/bulletshapemanager.cpp @@ -83,7 +83,8 @@ public: return osg::ref_ptr(); osg::ref_ptr shape (new BulletShape); - btBvhTriangleMeshShape* triangleMeshShape = new TriangleMeshShape(mTriangleMesh.release(), true); + + auto triangleMeshShape = std::make_unique(mTriangleMesh.release(), true); btVector3 aabbMin = triangleMeshShape->getLocalAabbMin(); btVector3 aabbMax = triangleMeshShape->getLocalAabbMax(); shape->mCollisionBox.mExtents[0] = (aabbMax[0] - aabbMin[0]) / 2.0f; @@ -92,7 +93,7 @@ public: shape->mCollisionBox.mCenter = osg::Vec3f( (aabbMax[0] + aabbMin[0]) / 2.0f, (aabbMax[1] + aabbMin[1]) / 2.0f, (aabbMax[2] + aabbMin[2]) / 2.0f ); - shape->mCollisionShape.reset(triangleMeshShape); + shape->mCollisionShape.reset(triangleMeshShape.release()); return shape; }