Skip to content

Commit 89b07f6

Browse files
author
iRobot ROS
authored
Merge pull request #38 from mauropasse/mauro/clean-events-executor
Implement no-op on IPC subscription
2 parents 3d7deb8 + 51bd25c commit 89b07f6

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

rclcpp/include/rclcpp/any_subscription_callback.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff 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);

rclcpp/include/rclcpp/experimental/buffers/ring_buffer_implementation.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff 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_]);

0 commit comments

Comments
 (0)