Skip to content

Commit

Permalink
Backport #188: Fix crash when using BVH animations (#199)
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 ee6fe52
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
9 changes: 9 additions & 0 deletions graphics/include/ignition/common/SkeletonAnimation.hh
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ namespace ignition
/// the animations
public: ~SkeletonAnimation();

// NOTE: this is not needed starting in ign-common4 since ign-common4 uses
// the IGN_UTILS_IMPL_PTR instead of a raw impl pointer. So, this
// method should not be included in forward ports from ign-common3 to
// ign-common4
/// \brief Assignment operator
/// \param[in] _other The new SkeletonAnimation
/// \return A reference to this instance
public: SkeletonAnimation &operator=(const SkeletonAnimation &_other);

/// \brief Changes the name
/// \param[in] _name the new name
public: void SetName(const std::string& _name);
Expand Down
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
13 changes: 13 additions & 0 deletions graphics/src/SkeletonAnimation.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,19 @@ SkeletonAnimation::~SkeletonAnimation()
this->data = NULL;
}

//////////////////////////////////////////////////
SkeletonAnimation &SkeletonAnimation::operator=(const SkeletonAnimation &_other)
{
if (this == &_other)
return *this;

this->data->name = _other.data->name;
this->data->length = _other.data->length;
this->data->animations = _other.data->animations;

return *this;
}

//////////////////////////////////////////////////
void SkeletonAnimation::SetName(const std::string &_name)
{
Expand Down

0 comments on commit ee6fe52

Please sign in to comment.