From 1b031ecb96ad180f9c790fbdc1270129ee063540 Mon Sep 17 00:00:00 2001 From: ChenYing Kuo Date: Sat, 19 Oct 2024 07:28:00 +0800 Subject: [PATCH 1/2] Shutdown explicitly while existing Signed-off-by: ChenYing Kuo --- ros_gz_sim/src/create.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ros_gz_sim/src/create.cpp b/ros_gz_sim/src/create.cpp index 83aca0af..4ae239dc 100644 --- a/ros_gz_sim/src/create.cpp +++ b/ros_gz_sim/src/create.cpp @@ -261,11 +261,13 @@ int main(int _argc, char ** _argv) if (node.Request(service, req, timeout, rep, result)) { if (result && rep.data()) { RCLCPP_INFO(ros2_node->get_logger(), "Entity creation successfull."); + rclcpp::shutdown(); return 0; } else { RCLCPP_ERROR( ros2_node->get_logger(), "Entity creation failed.\n %s", req.DebugString().c_str()); + rclcpp::shutdown(); return 1; } } else { @@ -275,5 +277,6 @@ int main(int _argc, char ** _argv) } } RCLCPP_INFO(ros2_node->get_logger(), "Entity creation was interrupted."); + rclcpp::shutdown(); return 0; } From aa68eb3b8b1f7e873d5752d3eb903f328a628c42 Mon Sep 17 00:00:00 2001 From: ChenYing Kuo Date: Fri, 25 Oct 2024 14:55:41 +0800 Subject: [PATCH 2/2] Incorporate the review comments. Signed-off-by: ChenYing Kuo --- ros_gz_sim/src/create.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ros_gz_sim/src/create.cpp b/ros_gz_sim/src/create.cpp index 4ae239dc..16dcff53 100644 --- a/ros_gz_sim/src/create.cpp +++ b/ros_gz_sim/src/create.cpp @@ -158,11 +158,13 @@ int main(int _argc, char ** _argv) if (!executed) { RCLCPP_INFO(ros2_node->get_logger(), "Timed out when getting world names."); + rclcpp::shutdown(); return -1; } if (!result || worlds_msg.data().empty()) { RCLCPP_INFO(ros2_node->get_logger(), "Failed to get world names."); + rclcpp::shutdown(); return -1; } @@ -185,6 +187,7 @@ int main(int _argc, char ** _argv) } else if (!topic_name.empty()) { // set XML string by fetching it from the given topic if (!set_XML_from_topic(topic_name, ros2_node, req)) { + rclcpp::shutdown(); return -1; } } else if (filtered_arguments.size() > 1) { @@ -200,6 +203,7 @@ int main(int _argc, char ** _argv) } else { RCLCPP_ERROR( ros2_node->get_logger(), "Failed to get XML from param [%s].", FLAGS_param.c_str()); + rclcpp::shutdown(); return -1; } } else if (!FLAGS_string.empty()) { // string @@ -207,11 +211,13 @@ int main(int _argc, char ** _argv) } else if (!FLAGS_topic.empty()) { // topic // set XML string by fetching it from the given topic if (!set_XML_from_topic(FLAGS_topic, ros2_node, req)) { + rclcpp::shutdown(); return -1; } } else { RCLCPP_ERROR( ros2_node->get_logger(), "Must specify either -file, -param, -string or -topic"); + rclcpp::shutdown(); return -1; } // TODO(azeey) Deprecate use of command line flags in ROS 2 K-turtle in @@ -219,6 +225,7 @@ int main(int _argc, char ** _argv) } else { RCLCPP_ERROR( ros2_node->get_logger(), "Must specify either file, string or topic as ROS 2 parameters"); + rclcpp::shutdown(); return -1; }