Skip to content

Commit

Permalink
Fix crash when using BVH animations
Browse files Browse the repository at this point in the history
Signed-off-by: Louise Poubel <[email protected]>
  • Loading branch information
chapulina committed Mar 25, 2021
1 parent b68fd3a commit 650892d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions graphics/src/Skeleton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ignition::common::Skeleton::Implementation
RawNodeWeights;

/// \brief the root node
public: SkeletonNode *root;
public: SkeletonNode *root{nullptr};

/// \brief The dictionary of nodes, indexed by name
public: SkeletonNodeMap nodes;
Expand Down Expand Up @@ -68,7 +68,6 @@ class ignition::common::Skeleton::Implementation
Skeleton::Skeleton()
: dataPtr(ignition::utils::MakeUniqueImpl<Implementation>())
{
this->dataPtr->root = nullptr;
}

//////////////////////////////////////////////////
Expand All @@ -82,10 +81,13 @@ Skeleton::Skeleton(SkeletonNode *_root)
//////////////////////////////////////////////////
Skeleton::~Skeleton()
{
for (auto& kv : this->dataPtr->nodes)
for (auto &kv : this->dataPtr->nodes)
delete kv.second;
for (auto& a : this->dataPtr->anims)
this->dataPtr->nodes.clear();

for (auto &a : this->dataPtr->anims)
delete a;
this->dataPtr->anims.clear();
}

//////////////////////////////////////////////////
Expand Down Expand Up @@ -462,7 +464,10 @@ bool Skeleton::AddBvhAnimation(const std::string &_bvhFile, double _scale)
* math::Matrix4d(skinNode->Transform().Rotation());
}

this->dataPtr->anims.push_back(skel->Animation(0u));
// Copy pointer from temp skeleton before it's deleted
auto newAnim = new SkeletonAnimation(skel->Animation(0u)->Name());
*newAnim = *skel->Animation(0u);
this->dataPtr->anims.push_back(newAnim);
this->dataPtr->mapAnimSkin.push_back(skelMap);
this->dataPtr->alignTranslate.push_back(translations);
this->dataPtr->alignRotate.push_back(rotations);
Expand Down

0 comments on commit 650892d

Please sign in to comment.