Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when using BVH animations #188

Merged
merged 1 commit into from
Mar 25, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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