From 5632fa03aee5ef831f0b6eded1eb13b6236142dc Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Wed, 27 May 2020 20:48:26 +0000 Subject: [PATCH] Hold onto the rcl_{subscription,publisher}_t shared_ptr. This keeps it from going out of scope while the executor is still dealing with QoSEvents. Signed-off-by: Chris Lalancette --- rclcpp/include/rclcpp/publisher_base.hpp | 5 +++-- rclcpp/include/rclcpp/qos_event.hpp | 8 +++++--- rclcpp/include/rclcpp/subscription_base.hpp | 5 +++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/rclcpp/include/rclcpp/publisher_base.hpp b/rclcpp/include/rclcpp/publisher_base.hpp index 0afe29b..48ebfea 100644 --- a/rclcpp/include/rclcpp/publisher_base.hpp +++ b/rclcpp/include/rclcpp/publisher_base.hpp @@ -200,10 +200,11 @@ protected: const EventCallbackT & callback, const rcl_publisher_event_type_t event_type) { - auto handler = std::make_shared>( + auto handler = std::make_shared>>( callback, rcl_publisher_event_init, - publisher_handle_.get(), + publisher_handle_, event_type); event_handlers_.emplace_back(handler); } diff --git a/rclcpp/include/rclcpp/qos_event.hpp b/rclcpp/include/rclcpp/qos_event.hpp index ad011f8..a43d904 100644 --- a/rclcpp/include/rclcpp/qos_event.hpp +++ b/rclcpp/include/rclcpp/qos_event.hpp @@ -102,11 +102,11 @@ protected: size_t wait_set_event_index_; }; -template +template class QOSEventHandler : public QOSEventHandlerBase { public: - template + template QOSEventHandler( const EventCallbackT & callback, InitFuncT init_func, @@ -114,8 +114,9 @@ public: EventTypeEnum event_type) : event_callback_(callback) { + parent_handle_ = parent_handle; event_handle_ = rcl_get_zero_initialized_event(); - rcl_ret_t ret = init_func(&event_handle_, parent_handle, event_type); + rcl_ret_t ret = init_func(&event_handle_, parent_handle.get(), event_type); if (ret != RCL_RET_OK) { if (ret == RCL_RET_UNSUPPORTED) { UnsupportedEventTypeException exc(ret, rcl_get_error_state(), "Failed to initialize event"); @@ -148,6 +149,7 @@ private: using EventCallbackInfoT = typename std::remove_reference::template argument_type<0>>::type; + ParentHandleT parent_handle_; EventCallbackT event_callback_; }; diff --git a/rclcpp/include/rclcpp/subscription_base.hpp b/rclcpp/include/rclcpp/subscription_base.hpp index 84bb127..cb560d6 100644 --- a/rclcpp/include/rclcpp/subscription_base.hpp +++ b/rclcpp/include/rclcpp/subscription_base.hpp @@ -270,10 +270,11 @@ protected: const EventCallbackT & callback, const rcl_subscription_event_type_t event_type) { - auto handler = std::make_shared>( + auto handler = std::make_shared>>( callback, rcl_subscription_event_init, - get_subscription_handle().get(), + get_subscription_handle(), event_type); qos_events_in_use_by_wait_set_.insert(std::make_pair(handler.get(), false)); event_handlers_.emplace_back(handler);