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 issue with removing skeletons without shapes #1625

Merged

Conversation

azeey
Copy link
Contributor

@azeey azeey commented Dec 17, 2021

Description copied from gazebo-forks#4

When subscribeTo is called with a skeleton in addSkeleton, the skeleton is added to mSkeletonSources. However, inside removeSkeleton, unsubscribeFrom is not called. Instead, removeShapeFrameOf is called. This is fine for most cases, but it fails to remove the skeleton from mSkeletonSources if the skeleton does not have any shapes within it. This causes mSkeletonSources to grow indefinitely. A hazardous side effect of this is that when an attempt is made to add a new skeleton via subscribeTo, the address of the skeleton might be the same as one of the stale entries in mSkeletonSources. Consequently, the new skeleton's shapes don't get added to the collision detection engine and very surprising results follow.

Here's a print out of mSkeletonSources after running several load/unload cycles via the levels feature of ign-gazebo where skeletons are removed and added repeatedly: https://gist.github.com/azeey/8fe5a55d19758923ef7c1b5df90869d3

And here's the collision detection failing (failure after the 4th cycle):
Peek 2020-01-27 19-22


Before creating a pull request

  • Document new methods and classes
  • Format new code files using clang-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

When `subscribeTo` is called with a skeleton in `addSkeleton`, the
skeleton is added to `mSkeletonSources`. However, inside
`removeSkeleton`, `unsubscribeFrom` is not called. Instead,
`removeShapeFrameOf` is called. This is fine for most cases, but if it
fails to remove the skeleton from `mSkeletonSources` if the skeleton
does not have any shapes within it. This causes `mSkeletonSources` to
grow indefinitely. A hazardous side effect of this is that when an
attempt is made to add a new skeleton via `subscribeTo`, the address of
the skeleton might be the same as one of the stale entries in
`mSkeletonSources`. Consequently, the new skeleton's shapes don't get
added to the collision detection engine and very surprising results
follow.

Signed-off-by: Addisu Z. Taddese <[email protected]>
@jslee02 jslee02 added this to the DART 6.13.0 milestone Dec 18, 2021
dart/collision/CollisionGroup.hpp Outdated Show resolved Hide resolved
dart/collision/CollisionGroup.hpp Outdated Show resolved Hide resolved
dart/collision/CollisionGroup.hpp Outdated Show resolved Hide resolved
boxShape);

// Needed to update subscribtions
world->step(1);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
world->step(1);
world->step();

I guess you use 1 as the parameter to take a single simulation step, presuming from the gazebo API, but the parameter of World::step() is boolean to set whether reset the commands (e.g., joint forces). You can safely omit the parameter in that case since the function takes single step anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, you guessed right 😄. Removed the parameter in bc78a37.

unittests/unit/test_CollisionGroups.cpp Outdated Show resolved Hide resolved
Signed-off-by: Addisu Z. Taddese <[email protected]>
Copy link
Member

@jslee02 jslee02 left a comment

Choose a reason for hiding this comment

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

LGTM! Let me create a new PR for updating the changelog for this PR

@jslee02 jslee02 merged commit 3e0edda into dartsim:main Dec 18, 2021
j-rivero added a commit to gazebo-release/dart-for-gz-gbp that referenced this pull request Sep 19, 2023
Upstream reviewed and merged the following patches that are important
for the robotics community:
 * Fix grouping of contact constraints
   dartsim/dart#1624
 * Fix issue with removing skeletons without shapes
   dartsim/dart#1625

Add them in d/patches since upstream does not provide patch releases
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.

2 participants