diff --git a/depth_image_proc/src/point_cloud_xyz.cpp b/depth_image_proc/src/point_cloud_xyz.cpp index f7ddc975f..4fde5594d 100644 --- a/depth_image_proc/src/point_cloud_xyz.cpp +++ b/depth_image_proc/src/point_cloud_xyz.cpp @@ -71,7 +71,10 @@ PointCloudXyzNode::PointCloudXyzNode(const rclcpp::NodeOptions & options) { std::lock_guard lock(connect_mutex_); if (s.current_count == 0) { - sub_depth_.shutdown(); + // Reset the subscriber instead of calling shutdown(): shutdown() leaves the + // synchronization check timer of the CameraSubscriber running, which crashes + // when it fires after the subscriptions are destroyed. + sub_depth_ = image_transport::CameraSubscriber(); } else if (!sub_depth_) { // For compressed topics to remap appropriately, we need to pass a // fully expanded and remapped topic name to image_transport diff --git a/depth_image_proc/src/point_cloud_xyz_radial.cpp b/depth_image_proc/src/point_cloud_xyz_radial.cpp index 9b1270edb..d71967c29 100644 --- a/depth_image_proc/src/point_cloud_xyz_radial.cpp +++ b/depth_image_proc/src/point_cloud_xyz_radial.cpp @@ -61,7 +61,10 @@ PointCloudXyzRadialNode::PointCloudXyzRadialNode(const rclcpp::NodeOptions & opt { std::lock_guard lock(connect_mutex_); if (s.current_count == 0) { - sub_depth_.shutdown(); + // Reset the subscriber instead of calling shutdown(): shutdown() leaves the + // synchronization check timer of the CameraSubscriber running, which crashes + // when it fires after the subscriptions are destroyed. + sub_depth_ = image_transport::CameraSubscriber(); } else if (!sub_depth_) { // For compressed topics to remap appropriately, we need to pass a // fully expanded and remapped topic name to image_transport diff --git a/image_proc/src/crop_decimate.cpp b/image_proc/src/crop_decimate.cpp index 98b2161a7..ecb77a492 100644 --- a/image_proc/src/crop_decimate.cpp +++ b/image_proc/src/crop_decimate.cpp @@ -137,7 +137,10 @@ CropDecimateNode::CropDecimateNode(const rclcpp::NodeOptions & options) [this](rclcpp::MatchedInfo &) { if (pub_.getNumSubscribers() == 0) { - sub_.shutdown(); + // Reset the subscriber instead of calling shutdown(): shutdown() leaves the + // synchronization check timer of the CameraSubscriber running, which crashes + // when it fires after the subscriptions are destroyed. + sub_ = image_transport::CameraSubscriber(); } else if (!sub_) { // Create subscriber with QoS matched to subscribed topic publisher auto qos_profile = getQosProfile(this, image_topic_); diff --git a/image_proc/src/rectify.cpp b/image_proc/src/rectify.cpp index 4adc67bef..a6cf73dc3 100644 --- a/image_proc/src/rectify.cpp +++ b/image_proc/src/rectify.cpp @@ -69,7 +69,10 @@ RectifyNode::RectifyNode(const rclcpp::NodeOptions & options) [this](rclcpp::MatchedInfo &) { if (pub_rect_.getNumSubscribers() == 0) { - sub_camera_.shutdown(); + // Reset the subscriber instead of calling shutdown(): shutdown() leaves the + // synchronization check timer of the CameraSubscriber running, which crashes + // when it fires after the subscriptions are destroyed. + sub_camera_ = image_transport::CameraSubscriber(); } else if (!sub_camera_) { // Create subscriber with QoS matched to subscribed topic publisher auto qos_profile = getQosProfile(this, image_topic_); diff --git a/image_proc/src/resize.cpp b/image_proc/src/resize.cpp index 68624ba90..01b7cbdba 100644 --- a/image_proc/src/resize.cpp +++ b/image_proc/src/resize.cpp @@ -72,7 +72,10 @@ ResizeNode::ResizeNode(const rclcpp::NodeOptions & options) [this](rclcpp::MatchedInfo &) { if (pub_image_.getNumSubscribers() == 0) { - sub_image_.shutdown(); + // Reset the subscriber instead of calling shutdown(): shutdown() leaves the + // synchronization check timer of the CameraSubscriber running, which crashes + // when it fires after the subscriptions are destroyed. + sub_image_ = image_transport::CameraSubscriber(); } else if (!sub_image_) { // Create subscriber with QoS matched to subscribed topic publisher auto qos_profile = getQosProfile(this, image_topic_); diff --git a/image_proc/src/track_marker.cpp b/image_proc/src/track_marker.cpp index 34197a770..0432f6b21 100644 --- a/image_proc/src/track_marker.cpp +++ b/image_proc/src/track_marker.cpp @@ -80,7 +80,10 @@ TrackMarkerNode::TrackMarkerNode(const rclcpp::NodeOptions & options) [this](rclcpp::MatchedInfo &) { if (pub_->get_subscription_count() == 0) { - sub_camera_.shutdown(); + // Reset the subscriber instead of calling shutdown(): shutdown() leaves the + // synchronization check timer of the CameraSubscriber running, which crashes + // when it fires after the subscriptions are destroyed. + sub_camera_ = image_transport::CameraSubscriber(); } else if (!sub_camera_) { // Create subscriber with QoS matched to subscribed topic publisher auto qos_profile = getQosProfile(this, image_topic_); diff --git a/image_rotate/src/image_flip.cpp b/image_rotate/src/image_flip.cpp index dd52a39f0..83fd96eac 100644 --- a/image_rotate/src/image_flip.cpp +++ b/image_rotate/src/image_flip.cpp @@ -188,11 +188,17 @@ void ImageFlipNode::onInit() if (img_pub_ && img_pub_.getNumSubscribers() == 0) { RCLCPP_DEBUG(get_logger(), "Unsubscribing from image topic."); img_sub_.shutdown(); - cam_sub_.shutdown(); + // Reset the subscriber instead of calling shutdown(): shutdown() leaves the + // synchronization check timer of the CameraSubscriber running, which crashes + // when it fires after the subscriptions are destroyed. + cam_sub_ = image_transport::CameraSubscriber(); } else if (cam_pub_ && cam_pub_.getNumSubscribers() == 0) { RCLCPP_DEBUG(get_logger(), "Unsubscribing from image topic."); img_sub_.shutdown(); - cam_sub_.shutdown(); + // Reset the subscriber instead of calling shutdown(): shutdown() leaves the + // synchronization check timer of the CameraSubscriber running, which crashes + // when it fires after the subscriptions are destroyed. + cam_sub_ = image_transport::CameraSubscriber(); } else { // For compressed topics to remap appropriately, we need to pass a // fully expanded and remapped topic name to image_transport diff --git a/image_rotate/src/image_rotate_node.cpp b/image_rotate/src/image_rotate_node.cpp index c390b20a3..a23248407 100644 --- a/image_rotate/src/image_rotate_node.cpp +++ b/image_rotate/src/image_rotate_node.cpp @@ -291,7 +291,10 @@ void ImageRotateNode::onInit() if (img_pub_.getNumSubscribers() == 0) { RCLCPP_DEBUG(get_logger(), "Unsubscribing from image topic."); img_sub_.shutdown(); - cam_sub_.shutdown(); + // Reset the subscriber instead of calling shutdown(): shutdown() leaves the + // synchronization check timer of the CameraSubscriber running, which crashes + // when it fires after the subscriptions are destroyed. + cam_sub_ = image_transport::CameraSubscriber(); } else { // For compressed topics to remap appropriately, we need to pass a // fully expanded and remapped topic name to image_transport