Skip to content

Commit 9df1b38

Browse files
committed
Fix issue #515: reactive sequence not skipped correctly
1 parent 374dd39 commit 9df1b38

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

src/controls/reactive_sequence.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ namespace BT
1717
NodeStatus ReactiveSequence::tick()
1818
{
1919
size_t success_count = 0;
20-
size_t running_count = 0;
2120

2221
for (size_t index = 0; index < childrenCount(); index++)
2322
{
@@ -33,8 +32,8 @@ NodeStatus ReactiveSequence::tick()
3332
switch (child_status)
3433
{
3534
case NodeStatus::RUNNING: {
36-
running_count++;
37-
35+
// just in case, make sure that following children are not
36+
// in RUNNING state too
3837
for (size_t i = index + 1; i < childrenCount(); i++)
3938
{
4039
haltChild(i);
@@ -65,11 +64,9 @@ NodeStatus ReactiveSequence::tick()
6564
if (success_count == childrenCount())
6665
{
6766
resetChildren();
68-
69-
// Skip if ALL the nodes have been skipped
70-
return status() == (NodeStatus::RUNNING) ? NodeStatus::SUCCESS : NodeStatus::SKIPPED;
7167
}
72-
throw LogicError("ReactiveSequence is not supposed to reach this point");
68+
// Skip if ALL the nodes have been skipped
69+
return status() == (NodeStatus::RUNNING) ? NodeStatus::SUCCESS : NodeStatus::SKIPPED;
7370
}
7471

7572
} // namespace BT

tests/gtest_skipping.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,3 +93,24 @@ TEST(SkippingLogic, SkipSubtree)
9393
ASSERT_EQ(status, NodeStatus::SUCCESS);
9494
}
9595

96+
TEST(SkippingLogic, ReactiveSingleChild)
97+
{
98+
99+
static const char* xml_text = R"(
100+
<root BTCPP_format="4">
101+
<BehaviorTree ID="Untitled">
102+
<ReactiveSequence>
103+
<AlwaysSuccess _skipIf="flag"/>
104+
</ReactiveSequence>
105+
</BehaviorTree>
106+
</root>
107+
)";
108+
109+
BT::BehaviorTreeFactory factory;
110+
auto root_blackboard = BT::Blackboard::create();
111+
root_blackboard->set<bool>("flag", true);
112+
113+
auto tree = factory.createTreeFromText(xml_text, root_blackboard);
114+
115+
tree.tickWhileRunning();
116+
}

0 commit comments

Comments
 (0)