From df5a81fb4ce606b6e41c637db7f690e52a693bd0 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 10:16:04 +0200 Subject: [PATCH] Don't crash if a wrong config was detected (#324) (#330) 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 --- ign_ros2_control/src/ign_ros2_control_plugin.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ign_ros2_control/src/ign_ros2_control_plugin.cpp b/ign_ros2_control/src/ign_ros2_control_plugin.cpp index ca58f9fe..7ebcfcb2 100644 --- a/ign_ros2_control/src/ign_ros2_control_plugin.cpp +++ b/ign_ros2_control/src/ign_ros2_control_plugin.cpp @@ -235,6 +235,9 @@ IgnitionROS2ControlPlugin::IgnitionROS2ControlPlugin() IgnitionROS2ControlPlugin::~IgnitionROS2ControlPlugin() { // 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(); @@ -483,6 +486,9 @@ void IgnitionROS2ControlPlugin::PreUpdate( const ignition::gazebo::UpdateInfo & _info, ignition::gazebo::EntityComponentManager & /*_ecm*/) { + if (!this->dataPtr->controller_manager_) { + return; + } static bool warned{false}; if (!warned) { rclcpp::Duration gazebo_period(_info.dt); @@ -517,6 +523,9 @@ void IgnitionROS2ControlPlugin::PostUpdate( const ignition::gazebo::UpdateInfo & _info, const ignition::gazebo::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);