From 2de38142e249dfc5d7c9e688ea492480d1012393 Mon Sep 17 00:00:00 2001 From: elsid Date: Wed, 11 Jul 2018 00:13:32 +0300 Subject: [PATCH] Replace raw pointers by unique_ptr --- components/nifbullet/bulletnifloader.cpp | 31 +++++++++++++++--------- components/nifbullet/bulletnifloader.hpp | 4 +-- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/components/nifbullet/bulletnifloader.cpp b/components/nifbullet/bulletnifloader.cpp index 3f033967cd..82d27269f8 100644 --- a/components/nifbullet/bulletnifloader.cpp +++ b/components/nifbullet/bulletnifloader.cpp @@ -47,8 +47,8 @@ namespace NifBullet { BulletNifLoader::BulletNifLoader() - : mCompoundShape(NULL) - , mStaticMesh(NULL) + : mCompoundShape() + , mStaticMesh() { } @@ -84,10 +84,11 @@ osg::ref_ptr BulletNifLoader::load(const Nif::File& nif) { std::unique_ptr compound (new btCompoundShape); - btBoxShape* boxShape = new btBoxShape(getbtVector(mShape->mCollisionBoxHalfExtents)); + std::unique_ptr boxShape(new btBoxShape(getbtVector(mShape->mCollisionBoxHalfExtents))); btTransform transform = btTransform::getIdentity(); transform.setOrigin(getbtVector(mShape->mCollisionBoxTranslate)); - compound->addChildShape(transform, boxShape); + compound->addChildShape(transform, boxShape.get()); + boxShape.release(); mShape->mCollisionShape = compound.release(); return mShape; @@ -108,16 +109,20 @@ osg::ref_ptr BulletNifLoader::load(const Nif::File& nif) if (mCompoundShape) { - mShape->mCollisionShape = mCompoundShape; if (mStaticMesh) { btTransform trans; trans.setIdentity(); - mCompoundShape->addChildShape(trans, new Resource::TriangleMeshShape(mStaticMesh,true)); + mCompoundShape->addChildShape(trans, new Resource::TriangleMeshShape(mStaticMesh.get(), true)); + mStaticMesh.release(); } + mShape->mCollisionShape = mCompoundShape.release(); } else if (mStaticMesh) - mShape->mCollisionShape = new Resource::TriangleMeshShape(mStaticMesh,true); + { + mShape->mCollisionShape = new Resource::TriangleMeshShape(mStaticMesh.get(), true); + mStaticMesh.release(); + } return mShape; } @@ -277,9 +282,9 @@ void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags, if (isAnimated) { if (!mCompoundShape) - mCompoundShape = new btCompoundShape(); + mCompoundShape.reset(new btCompoundShape); - btTriangleMesh* childMesh = new btTriangleMesh(); + std::unique_ptr childMesh(new btTriangleMesh); const Nif::NiTriShapeData *data = shape->data.getPtr(); @@ -297,7 +302,8 @@ void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags, childMesh->addTriangle(getbtVector(b1), getbtVector(b2), getbtVector(b3)); } - Resource::TriangleMeshShape* childShape = new Resource::TriangleMeshShape(childMesh,true); + std::unique_ptr childShape(new Resource::TriangleMeshShape(childMesh.get(), true)); + childMesh.release(); float scale = shape->trafo.scale; const Nif::Node* parent = shape; @@ -314,12 +320,13 @@ void BulletNifLoader::handleNiTriShape(const Nif::NiTriShape *shape, int flags, mShape->mAnimatedShapes.insert(std::make_pair(shape->recIndex, mCompoundShape->getNumChildShapes())); - mCompoundShape->addChildShape(trans, childShape); + mCompoundShape->addChildShape(trans, childShape.get()); + childShape.release(); } else { if (!mStaticMesh) - mStaticMesh = new btTriangleMesh(false); + mStaticMesh.reset(new btTriangleMesh(false)); // Static shape, just transform all vertices into position const Nif::NiTriShapeData *data = shape->data.getPtr(); diff --git a/components/nifbullet/bulletnifloader.hpp b/components/nifbullet/bulletnifloader.hpp index 22d228d106..44134fd238 100644 --- a/components/nifbullet/bulletnifloader.hpp +++ b/components/nifbullet/bulletnifloader.hpp @@ -61,9 +61,9 @@ private: void handleNiTriShape(const Nif::NiTriShape *shape, int flags, const osg::Matrixf& transform, bool isAnimated); - btCompoundShape* mCompoundShape; + std::unique_ptr mCompoundShape; - btTriangleMesh* mStaticMesh; + std::unique_ptr mStaticMesh; osg::ref_ptr mShape; };