Skip to content

Commit 8d9fa4c

Browse files
authored
fix(tier4_planning_rviz_plugin): fix plugin crash (#3830)
* preVisualizePathFootPrint is the cause Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp> * update ogre_node and text_ptr in each iteration Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp> --------- Signed-off-by: Mamoru Sobue <mamoru.sobue@tier4.jp>
1 parent 35a346d commit 8d9fa4c

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

common/tier4_planning_rviz_plugin/src/path/display.cpp

+15-17
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,21 @@ void AutowarePathWithLaneIdDisplay::preVisualizePathFootprintDetail(
5353
const autoware_auto_planning_msgs::msg::PathWithLaneId::ConstSharedPtr msg_ptr)
5454
{
5555
const size_t size = msg_ptr->points.size();
56-
if (size > lane_id_obj_ptrs_.size()) {
57-
for (std::size_t i = lane_id_obj_ptrs_.size(); i < size; i++) {
58-
std::unique_ptr<Ogre::SceneNode> node_ptr;
59-
node_ptr.reset(scene_node_->createChildSceneNode());
60-
auto text_ptr =
61-
std::make_unique<rviz_rendering::MovableText>("not initialized", "Liberation Sans", 0.1);
62-
text_ptr->setVisible(false);
63-
text_ptr->setTextAlignment(
64-
rviz_rendering::MovableText::H_CENTER, rviz_rendering::MovableText::V_ABOVE);
65-
node_ptr->attachObject(text_ptr.get());
66-
lane_id_obj_ptrs_.push_back(std::make_pair(std::move(node_ptr), std::move(text_ptr)));
67-
}
68-
} else {
69-
for (std::size_t i = lane_id_obj_ptrs_.size() - 1; i >= size; i--) {
70-
scene_node_->removeChild(lane_id_obj_ptrs_.at(i).first.get());
71-
}
72-
lane_id_obj_ptrs_.resize(size);
56+
// clear previous text
57+
for (const auto & [node_ptr, text_ptr] : lane_id_obj_ptrs_) {
58+
scene_node_->removeChild(node_ptr.get());
59+
}
60+
lane_id_obj_ptrs_.clear();
61+
for (std::size_t i = 0; i < size; i++) {
62+
std::unique_ptr<Ogre::SceneNode> node_ptr;
63+
node_ptr.reset(scene_node_->createChildSceneNode());
64+
auto text_ptr =
65+
std::make_unique<rviz_rendering::MovableText>("not initialized", "Liberation Sans", 0.1);
66+
text_ptr->setVisible(false);
67+
text_ptr->setTextAlignment(
68+
rviz_rendering::MovableText::H_CENTER, rviz_rendering::MovableText::V_ABOVE);
69+
node_ptr->attachObject(text_ptr.get());
70+
lane_id_obj_ptrs_.push_back(std::make_pair(std::move(node_ptr), std::move(text_ptr)));
7371
}
7472
}
7573

0 commit comments

Comments
 (0)