Skip to content

Commit 7522464

Browse files
committed
Fix issue #585
1 parent cd78d9e commit 7522464

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

include/behaviortree_cpp/action_node.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ class CoroActionNode : public ActionNodeBase
204204
// This method triggers the TickEngine. Do NOT remove the "final" keyword.
205205
virtual NodeStatus executeTick() override final;
206206

207+
// Used internally, but it needs to be public
207208
void tickImpl();
208209

209210
/** You may want to override this method. But still, remember to call this

src/action_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ NodeStatus CoroActionNode::executeTick()
123123

124124
void CoroActionNode::tickImpl()
125125
{
126-
setStatus(tick());
126+
setStatus(TreeNode::executeTick());
127127
}
128128

129129
void CoroActionNode::halt()

tests/gtest_preconditions.cpp

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,53 @@ TEST(Preconditions, Issue533)
175175
ASSERT_EQ(counters[1], 1);
176176
ASSERT_EQ(counters[2], 1);
177177
}
178+
179+
180+
class CoroTestNode: public BT::CoroActionNode
181+
{
182+
public:
183+
CoroTestNode(const std::string& node_name,
184+
const BT::NodeConfig& config) :
185+
BT::CoroActionNode(node_name, config)
186+
{}
187+
188+
virtual BT::NodeStatus tick() override
189+
{
190+
for(int i=0; i<10; i++) {
191+
times_ticked++;
192+
setStatusRunningAndYield();
193+
}
194+
return NodeStatus::SUCCESS;
195+
}
196+
197+
static PortsList providedPorts()
198+
{
199+
return {};
200+
}
201+
202+
int times_ticked = 0;
203+
};
204+
205+
206+
TEST(Preconditions, Issue585)
207+
{
208+
BehaviorTreeFactory factory;
209+
factory.registerNodeType<CoroTestNode>("CoroTest");
210+
211+
const std::string xml_text = R"(
212+
213+
<root BTCPP_format="4" >
214+
<BehaviorTree ID="MainTree">
215+
<Sequence>
216+
<Script code="A:=1" />
217+
<CoroTest _skipIf="A==1" />
218+
</Sequence>
219+
</BehaviorTree>
220+
</root>)";
221+
222+
auto tree = factory.createTreeFromText(xml_text);
223+
tree.tickWhileRunning();
224+
225+
auto coro = dynamic_cast<CoroTestNode*>(tree.subtrees.front()->nodes.back().get());
226+
ASSERT_EQ(coro->times_ticked, 0);
227+
}

0 commit comments

Comments
 (0)