From d38dfcfcd3d39435d4a6cb689593d183731216fc Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Tue, 20 Aug 2019 10:28:09 -0400 Subject: [PATCH] uORB::Subscription fix initialization but not yet published case - otherwise uORB::Subscription will erroneously report published after the first successful initialization of an unpublished topic --- src/modules/uORB/Subscription.hpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/modules/uORB/Subscription.hpp b/src/modules/uORB/Subscription.hpp index 2f3a26b379..47f87112c9 100644 --- a/src/modules/uORB/Subscription.hpp +++ b/src/modules/uORB/Subscription.hpp @@ -75,7 +75,22 @@ public: void unsubscribe(); bool valid() const { return _node != nullptr; } - bool published() { return valid() ? _node->is_published() : init(); } + bool published() + { + if (valid()) { + return _node->is_published(); + } + + // try to initialize + if (init()) { + // check again if valid + if (valid()) { + return _node->is_published(); + } + } + + return false; + } /** * Check if there is a new update.