Skip to content

Commit a851c79

Browse files
committed
overwrite previous tree definitions
1 parent faa684c commit a851c79

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

src/xml_parsing.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void XMLParser::Pimpl::loadDocImpl(tinyxml2::XMLDocument* doc, bool add_includes
222222
tree_name = "BehaviorTree_" + std::to_string(suffix_count++);
223223
}
224224

225-
tree_roots.insert({tree_name, bt_node});
225+
tree_roots[tree_name] = bt_node;
226226
}
227227
}
228228

@@ -430,10 +430,9 @@ void VerifyXML(const std::string& xml_text,
430430
}
431431

432432
Tree XMLParser::instantiateTree(const Blackboard::Ptr& root_blackboard,
433-
std::string main_tree_to_execute)
433+
std::string main_tree_ID)
434434
{
435435
Tree output_tree;
436-
std::string main_tree_ID = main_tree_to_execute;
437436

438437
// use the main_tree_to_execute argument if it was provided by the user
439438
// or the one in the FIRST document opened

tests/gtest_factory.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,3 +341,34 @@ TEST(
341341
Tree tree = factory.createTreeFromFile(path);
342342
ASSERT_EQ(NodeStatus::SUCCESS, tree.tickWhileRunning());
343343
}
344+
345+
TEST(BehaviorTreeReload, ReloadSameTree)
346+
{
347+
const char* xmlA = R"(
348+
<root main_tree_to_execute = "MainTree" >
349+
<BehaviorTree ID="MainTree">
350+
<AlwaysSuccess/>
351+
</BehaviorTree>
352+
</root> )";
353+
354+
const char* xmlB = R"(
355+
<root main_tree_to_execute = "MainTree" >
356+
<BehaviorTree ID="MainTree">
357+
<AlwaysFailure/>
358+
</BehaviorTree>
359+
</root> )";
360+
361+
BehaviorTreeFactory factory;
362+
363+
factory.registerBehaviorTreeFromText(xmlA);
364+
{
365+
auto tree = factory.createTree("MainTree");
366+
ASSERT_EQ(NodeStatus::SUCCESS, tree.tickWhileRunning());
367+
}
368+
369+
factory.registerBehaviorTreeFromText(xmlB);
370+
{
371+
auto tree = factory.createTree("MainTree");
372+
ASSERT_EQ(NodeStatus::FAILURE, tree.tickWhileRunning());
373+
}
374+
}

0 commit comments

Comments
 (0)