From 0e0144a54ac144bea281873ee55f66c2f41f000b Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 10:10:52 +0200 Subject: [PATCH] Don't crash if a wrong config was detected (#324) (#331) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit ec1b95893fa933cb3e2cc5341bb65dd621645785) Co-authored-by: Christoph Fröhlich Co-authored-by: Alejandro Hernández Cordero --- gz_ros2_control/src/gz_ros2_control_plugin.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gz_ros2_control/src/gz_ros2_control_plugin.cpp b/gz_ros2_control/src/gz_ros2_control_plugin.cpp index 54c3bb7b..5980e9d5 100644 --- a/gz_ros2_control/src/gz_ros2_control_plugin.cpp +++ b/gz_ros2_control/src/gz_ros2_control_plugin.cpp @@ -235,6 +235,9 @@ GazeboSimROS2ControlPlugin::GazeboSimROS2ControlPlugin() GazeboSimROS2ControlPlugin::~GazeboSimROS2ControlPlugin() { // Stop controller manager thread + if (!this->dataPtr->controller_manager_) { + return; + } this->dataPtr->executor_->remove_node(this->dataPtr->controller_manager_); this->dataPtr->executor_->cancel(); this->dataPtr->thread_executor_spin_.join(); @@ -514,6 +517,9 @@ void GazeboSimROS2ControlPlugin::PreUpdate( const sim::UpdateInfo & _info, sim::EntityComponentManager & /*_ecm*/) { + if (!this->dataPtr->controller_manager_) { + return; + } static bool warned{false}; if (!warned) { rclcpp::Duration gazebo_period(_info.dt); @@ -548,6 +554,9 @@ void GazeboSimROS2ControlPlugin::PostUpdate( const sim::UpdateInfo & _info, const sim::EntityComponentManager & /*_ecm*/) { + if (!this->dataPtr->controller_manager_) { + return; + } // Get the simulation time and period rclcpp::Time sim_time_ros(std::chrono::duration_cast( _info.simTime).count(), RCL_ROS_TIME);