Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 801a2e7

Browse files
Merge pull request BehaviorTree#549 from alsora/asoragna/fix-timeout-crash
fix std::system_error in TimeoutNode
2 parents 5fb41ce + c989b53 commit 801a2e7

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

include/behaviortree_cpp/decorators/timeout_node.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,15 @@ class TimeoutNode : public DecoratorNode
7777
if (msec_ > 0)
7878
{
7979
timer_id_ = timer_.add(std::chrono::milliseconds(msec_), [this](bool aborted) {
80+
// Return immediately if the timer was aborted.
81+
// This function could be invoked during destruction of this object and
82+
// we don't want to access member variables if not needed.
83+
if (aborted)
84+
{
85+
return;
86+
}
8087
std::unique_lock<std::mutex> lk(timeout_mutex_);
81-
if (!aborted && child()->status() == NodeStatus::RUNNING)
88+
if (child()->status() == NodeStatus::RUNNING)
8289
{
8390
child_halted_ = true;
8491
haltChild();

include/behaviortree_cpp/decorators/timer_queue.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ class TimerQueue
225225

226226
lk.unlock();
227227
if (item.handler)
228+
{
228229
item.handler(item.id == 0);
230+
}
229231
lk.lock();
230232
}
231233
}

0 commit comments

Comments
 (0)