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 WorldInteractiveMarkerViewer bug when removing Skeletons #252

Merged
merged 6 commits into from
Nov 19, 2017

Conversation

brianhou
Copy link
Contributor

@brianhou brianhou commented Oct 30, 2017

If a Skeleton is removed and a new Skeleton with the same name is added quickly enough (before the viewer refreshes and removes the original Skeleton), the new Skeleton is not visualized. This PR fixes this bug by using the actual SkeletonPtr as the key in WorldInteractiveMarkerViewer, rather than its name.

At some point, we could fix this by registering callbacks to World that are called when adding or removing Skeletons.


Before creating a pull request

  • Document new methods and classes
  • Format code with make format

Before merging a pull request

  • Set version target by selecting a milestone on the right side
  • Summarize this change in CHANGELOG.md
  • Add unit test(s) for this change

name.

Use the actual Skeleton as the key in WorldInteractiveMarkerViewer,
rather than the Skeleton's name.
@brianhou brianhou added this to the Aikido 0.2.0 milestone Oct 30, 2017
@codecov
Copy link

codecov bot commented Oct 30, 2017

Codecov Report

Merging #252 into master will not change coverage.
The diff coverage is 100%.

@@           Coverage Diff           @@
##           master     #252   +/-   ##
=======================================
  Coverage   70.43%   70.43%           
=======================================
  Files         181      181           
  Lines        5391     5391           
  Branches      847      847           
=======================================
  Hits         3797     3797           
  Misses       1074     1074           
  Partials      520      520
Impacted Files Coverage Δ
src/planner/World.cpp 82.53% <100%> (ø) ⬆️

@@ -39,6 +39,11 @@ class World
/// \param name Name of desired Skeleton
dart::dynamics::SkeletonPtr getSkeleton(const std::string& name) const;

/// Find a Skeleton by Skeleton, returning null if it is not in the World
/// \param skel Desired Skeleton
dart::dynamics::SkeletonPtr getSkeleton(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function sounds like checking whether the skeleton exists in (registered to) this world. I would like to suggest changing the function name containsSkeleton(...) or existsSkeleton(...) (or skeletonExists) (we conventionally suffix s to the leading verb for an inquiry function) like NewtonsMethodProjectable::contains and CatkinResourceRetriever::exists(...) and returning bool.

I personally prefer contains over exists because contains would sound more natural when we use the function like:

if (world.containsSkeleton(someSkeleton))
  ...
if (world.existsSkeleton(someSkeleton)) // or if(world.skeletonExists(...))
  ...

/// Find a Skeleton by Skeleton, returning null if it is not in the World
/// \param skel Desired Skeleton
dart::dynamics::SkeletonPtr getSkeleton(
const dart::dynamics::SkeletonPtr skel) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Let's use const dart::dynamics::SkeletonPtr& to avoid unnecessary increase of the reference count by copying std::shared_ptr<...>.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can use std::weak_ptr here because it is not comparable or hashable. This makes sense because an unlocked weak_ptr can spontaneously degrade to nullptr if all owning shared_ptrs are destructed.

We could using a const Skeleton* as the key. But we'd need to be careful to not access the pointer after the Skeleton is destructed, e.g. by lock()ing a std::weak_ptr that we store inside the marker instance.

/// Mapping of Skeleton names to SkeletonMarkers
std::map<std::string, SkeletonMarkerPtr> mSkeletonMarkers;
/// Mapping of Skeletons to SkeletonMarkers
std::map<dart::dynamics::SkeletonPtr, SkeletonMarkerPtr> mSkeletonMarkers;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this is a stopgap solution (over using callbacks), we might want to use std::weak_pointer<...> here because this class doesn't need to have the ownership as it just uses the skeletons only when they still exist in mWorld.

@jslee02
Copy link
Member

jslee02 commented Nov 2, 2017

Good catch! I made some suggestions.

Copy link
Member

@mkoval mkoval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 I agree with all of @jslee02's comments.

/// Find a Skeleton by Skeleton, returning null if it is not in the World
/// \param skel Desired Skeleton
dart::dynamics::SkeletonPtr getSkeleton(
const dart::dynamics::SkeletonPtr skel) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can use std::weak_ptr here because it is not comparable or hashable. This makes sense because an unlocked weak_ptr can spontaneously degrade to nullptr if all owning shared_ptrs are destructed.

We could using a const Skeleton* as the key. But we'd need to be careful to not access the pointer after the Skeleton is destructed, e.g. by lock()ing a std::weak_ptr that we store inside the marker instance.

@jslee02
Copy link
Member

jslee02 commented Nov 17, 2017

I changed the code according to the suggestions. @brianhou Could you take a look at the change for sure?

@brianhou brianhou merged commit 631e606 into master Nov 19, 2017
@brianhou brianhou deleted the bugfix/brianhou/worldviewer-removeskeleton branch November 19, 2017 03:05
gilwoolee pushed a commit that referenced this pull request Jan 21, 2019
* Fix bug from removing Skeletons, then adding new Skeletons with the same
name.

Use the actual Skeleton as the key in WorldInteractiveMarkerViewer,
rather than the Skeleton's name.

* Rename getSkeleton(skeleton) to hasSkeleton(skeleton)

* Update changelog

* Use hasSkeleton() instead of getSkeleton()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants