From e4f599575ececfe6c84f5bdf0ba2412405898c13 Mon Sep 17 00:00:00 2001 From: elsid Date: Sun, 17 Jul 2022 12:12:17 +0200 Subject: [PATCH] Use unique_ptr to manage Bone lifetime --- components/sceneutil/skeleton.cpp | 16 +++++----------- components/sceneutil/skeleton.hpp | 7 +------ 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/components/sceneutil/skeleton.cpp b/components/sceneutil/skeleton.cpp index 9f646ade5c..45ccefe6e5 100644 --- a/components/sceneutil/skeleton.cpp +++ b/components/sceneutil/skeleton.cpp @@ -80,15 +80,16 @@ Bone* Skeleton::getBone(const std::string &name) { if (bone->mChildren[i]->mNode == matrixTransform) { - child = bone->mChildren[i]; + child = bone->mChildren[i].get(); break; } } - if (!child) + if (child == nullptr) { - child = new Bone; - bone->mChildren.push_back(child); + auto childBone = std::make_unique(); + child = childBone.get(); + bone->mChildren.push_back(std::move(childBone)); mNeedToUpdateBoneMatrices = true; } bone = child; @@ -165,13 +166,6 @@ Bone::Bone() { } -Bone::~Bone() -{ - for (unsigned int i=0; i mChildren; + std::vector> mChildren; /// Update the skeleton-space matrix of this bone and all its children. void update(const osg::Matrixf* parentMatrixInSkeletonSpace); - - private: - Bone(const Bone&); - void operator=(const Bone&); }; /// @brief Handles the bone matrices for any number of child RigGeometries.