Skip to content

Commit

Permalink
Backport #188: Fix crash when using BVH animations
Browse files Browse the repository at this point in the history
Signed-off-by: Ashton Larkin <[email protected]>
  • Loading branch information
adlarkin committed Apr 28, 2021
1 parent f1c8c4a commit 674f112
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 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::SkeletonPrivate
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::SkeletonPrivate
Skeleton::Skeleton()
: data(new SkeletonPrivate)
{
this->data->root = nullptr;
}

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

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

delete this->data;
this->data = NULL;
}
Expand Down Expand Up @@ -463,7 +466,10 @@ bool Skeleton::AddBvhAnimation(const std::string &_bvhFile, double _scale)
* math::Matrix4d(skinNode->Transform().Rotation());
}

this->data->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->data->anims.push_back(newAnim);
this->data->mapAnimSkin.push_back(skelMap);
this->data->alignTranslate.push_back(translations);
this->data->alignRotate.push_back(rotations);
Expand Down

0 comments on commit 674f112

Please sign in to comment.