Skip to content

Commit 8ec8591

Browse files
author
Mauro Passerino
committed
Check if valid msg before dispatch
1 parent aab59a0 commit 8ec8591

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
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/subscription_intra_process.hpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,8 @@ class SubscriptionIntraProcess : public SubscriptionIntraProcessBase
129129

130130
if (any_callback_.use_take_shared_method()) {
131131
shared_msg = buffer_->consume_shared();
132-
if(!shared_msg) {
133-
return nullptr;
134-
}
135132
} else {
136133
unique_msg = buffer_->consume_unique();
137-
if(!unique_msg) {
138-
return nullptr;
139-
}
140134
}
141135
return std::static_pointer_cast<void>(
142136
std::make_shared<std::pair<ConstMessageSharedPtr, MessageUniquePtr>>(

0 commit comments

Comments
 (0)