Skip to content

Commit 02ea03e

Browse files
authored
Gracefully handle loops in TF tree (#1820)
TF display was segfaulting when a loop was introduced in the tree_category_.
1 parent 9911c32 commit 02ea03e

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/rviz/default_plugin/tf_display.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,17 @@ Ogre::ColourValue lerpColor(const Ogre::ColourValue& start, const Ogre::ColourVa
556556
return start * t + end * (1 - t);
557557
}
558558

559+
bool hasLoop(rviz::Property* child, rviz::Property* parent, rviz::Property* root)
560+
{
561+
while (child != root)
562+
{
563+
if (child == parent)
564+
return true;
565+
child = child->getParent();
566+
}
567+
return false;
568+
}
569+
559570
void TFDisplay::updateFrame(FrameInfo* frame)
560571
{
561572
auto tf = context_->getTF2BufferPtr();
@@ -736,7 +747,11 @@ void TFDisplay::updateFrame(FrameInfo* frame)
736747
// Retrieve tree property to add the new child at
737748
rviz::Property* parent_tree_property;
738749
if (parent && parent->tree_property_) // parent already created
750+
{
739751
parent_tree_property = parent->tree_property_;
752+
if (hasLoop(parent_tree_property, frame->tree_property_, tree_category_))
753+
parent_tree_property = tree_category_; // insert loops at root node
754+
}
740755
else // create (temporarily) at root
741756
parent_tree_property = tree_category_;
742757

0 commit comments

Comments
 (0)