File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -185,6 +185,12 @@ class AnySubscriptionCallback
185185 ConstMessageSharedPtr message, const rclcpp::MessageInfo & message_info)
186186 {
187187 TRACEPOINT (callback_start, static_cast <const void *>(this ), true );
188+
189+ // If the message is not valid, return.
190+ if (!message) {
191+ return ;
192+ }
193+
188194 if (const_shared_ptr_callback_) {
189195 const_shared_ptr_callback_ (message);
190196 } else if (const_shared_ptr_with_info_callback_) {
@@ -208,6 +214,12 @@ class AnySubscriptionCallback
208214 MessageUniquePtr message, const rclcpp::MessageInfo & message_info)
209215 {
210216 TRACEPOINT (callback_start, static_cast <const void *>(this ), true );
217+
218+ // If the message is not valid, return.
219+ if (!message) {
220+ return ;
221+ }
222+
211223 if (shared_ptr_callback_) {
212224 typename std::shared_ptr<MessageT> shared_message = std::move (message);
213225 shared_ptr_callback_ (shared_message);
Original file line number Diff line number Diff line change @@ -91,7 +91,12 @@ class RingBufferImplementation : public BufferImplementationBase<BufferT>
9191
9292 if (!has_data_ ()) {
9393 RCLCPP_ERROR (rclcpp::get_logger (" rclcpp" ), " Calling dequeue on empty intra-process buffer" );
94- throw std::runtime_error (" Calling dequeue on empty intra-process buffer" );
94+ // This situation can happen on the EventsExecutor if we have more events in the queue
95+ // than messages in the history cache (set by the qos_policies.depth of the subscription)
96+ // For example if we set depth=1 and we get 2 messages really fast (so no time for processing),
97+ // we could end up with 2 events in the queue but only 1 msg is actually stored on the buffer.
98+ // In this case we return an empty buffer.
99+ return BufferT ();
95100 }
96101
97102 auto request = std::move (ring_buffer_[read_index_]);
You can’t perform that action at this time.
0 commit comments