diff --git a/include/behaviortree_cpp/decorators/timeout_node.h b/include/behaviortree_cpp/decorators/timeout_node.h index eaf949698..d321b546e 100644 --- a/include/behaviortree_cpp/decorators/timeout_node.h +++ b/include/behaviortree_cpp/decorators/timeout_node.h @@ -77,8 +77,15 @@ class TimeoutNode : public DecoratorNode if (msec_ > 0) { timer_id_ = timer_.add(std::chrono::milliseconds(msec_), [this](bool aborted) { + // Return immediately if the timer was aborted. + // This function could be invoked during destruction of this object and + // we don't want to access member variables if not needed. + if (aborted) + { + return; + } std::unique_lock lk(timeout_mutex_); - if (!aborted && child()->status() == NodeStatus::RUNNING) + if (child()->status() == NodeStatus::RUNNING) { child_halted_ = true; haltChild(); diff --git a/include/behaviortree_cpp/decorators/timer_queue.h b/include/behaviortree_cpp/decorators/timer_queue.h index 0bcb1a8a0..ac514463c 100644 --- a/include/behaviortree_cpp/decorators/timer_queue.h +++ b/include/behaviortree_cpp/decorators/timer_queue.h @@ -225,7 +225,9 @@ class TimerQueue lk.unlock(); if (item.handler) + { item.handler(item.id == 0); + } lk.lock(); } }