Skip to content

Commit

Permalink
fix data race: prohibit resizeMap() during plugin/filter initializati…
Browse files Browse the repository at this point in the history
…on (#3522)

Co-authored-by: Dirk Braunschweiger <dirk.braunschweiger@symovo.de>
  • Loading branch information
2 people authored and SteveMacenski committed Jun 9, 2023
1 parent 49e0756 commit 7a25610
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions nav2_costmap_2d/src/costmap_2d_ros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,26 +153,38 @@ Costmap2DROS::on_configure(const rclcpp_lifecycle::State & /*state*/)
RCLCPP_INFO(get_logger(), "Using plugin \"%s\"", plugin_names_[i].c_str());

std::shared_ptr<Layer> plugin = plugin_loader_.createSharedInstance(plugin_types_[i]);

// lock the costmap because no update is allowed until the plugin is initialized
std::unique_lock<Costmap2D::mutex_t> lock(*(layered_costmap_->getCostmap()->getMutex()));

layered_costmap_->addPlugin(plugin);

// TODO(mjeronimo): instead of get(), use a shared ptr
plugin->initialize(
layered_costmap_.get(), plugin_names_[i], tf_buffer_.get(),
shared_from_this(), callback_group_);

lock.unlock();

RCLCPP_INFO(get_logger(), "Initialized plugin \"%s\"", plugin_names_[i].c_str());
}
// and costmap filters as well
for (unsigned int i = 0; i < filter_names_.size(); ++i) {
RCLCPP_INFO(get_logger(), "Using costmap filter \"%s\"", filter_names_[i].c_str());

std::shared_ptr<Layer> filter = plugin_loader_.createSharedInstance(filter_types_[i]);

// lock the costmap because no update is allowed until the filter is initialized
std::unique_lock<Costmap2D::mutex_t> lock(*(layered_costmap_->getCostmap()->getMutex()));

layered_costmap_->addFilter(filter);

filter->initialize(
layered_costmap_.get(), filter_names_[i], tf_buffer_.get(),
shared_from_this(), callback_group_);

lock.unlock();

RCLCPP_INFO(get_logger(), "Initialized costmap filter \"%s\"", filter_names_[i].c_str());
}

Expand Down

0 comments on commit 7a25610

Please sign in to comment.