Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/behaviortree_cpp/decorators/loop_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class LoopNode : public DecoratorNode
if(status() == NodeStatus::IDLE)
{
child_running_ = false;
current_queue_.reset();

// special case: the port contains a string that was converted to SharedQueue<T>
if(static_queue_)
{
Expand Down
36 changes: 36 additions & 0 deletions tests/gtest_loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,42 @@ TEST(LoopNode, RestartAfterCompletion)
ASSERT_EQ(tick_count, 3); // Should iterate over queue again
}

TEST(LoopNode, RestartAfterCompletion_VectorFromBlackboard)
{
BehaviorTreeFactory factory;

int tick_count = 0;
factory.registerSimpleAction("CountTicks", [&tick_count](TreeNode&) {
tick_count++;
return NodeStatus::SUCCESS;
});

const std::string xml_text = R"(
<root BTCPP_format="4">
<BehaviorTree>
<LoopInt queue="{my_vector}" value="{val}">
<CountTicks/>
</LoopInt>
</BehaviorTree>
</root>)";

auto tree = factory.createTreeFromText(xml_text);
tree.rootBlackboard()->set("my_vector", std::vector{ 1, 2, 3 });

// First execution
auto status = tree.tickWhileRunning();
ASSERT_EQ(status, NodeStatus::SUCCESS);
ASSERT_EQ(tick_count, 3);

// Reset and execute again
tree.haltTree();
tick_count = 0;
tree.rootBlackboard()->set("my_vector", std::vector{ 1, 2, 3 });
status = tree.tickWhileRunning();
ASSERT_EQ(status, NodeStatus::SUCCESS);
ASSERT_EQ(tick_count, 3); // Should iterate over vector again
}

// ============ convertFromString tests for SharedQueue ============

TEST(LoopNode, ConvertFromString_Int)
Expand Down
Loading