Detaching attached collision object bugfix #1438
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Detaching an attached collision object can cause segfaults in melodic.
The segfault was found running Melodic on 18.04
In this method,
attached_body
is a raw pointer to anAttachedBody
inrobot_state_
.The planning scene saves the
attached_body
'sshapes_
vector withconst std::vector<shapes::ShapeConstPtr>& shapes = attached_body->getShapes();
. However, whenrobot_state_->clearAttachedBody(name)
is called, it deletes theAttachedBody
causing the underlyingShapeConstPtr
s to be freed. Then whenworld_->addToObject(name, shapes, poses)
is called, it segfaults as the data in theshapes_
vector is no longer available.By moving
world_->addToObject(name, shapes, poses)
beforerobot_state_->clearAttachedBody(name)
, we create another shared pointer to the same underlying data in the shapes vector so that whenrobot_state_->clearAttachedBody(name)
is called, it does not free theShapeConstPtr
s.Another fix would be to use
const std::vector<shapes::ShapeConstPtr> shapes = attached_body->getShapes();
instead ofconst std::vector<shapes::ShapeConstPtr>& shapes = attached_body->getShapes();
but I think this fix is betterChecklist