Skip to content

Load external subtree from inline XML throws std::runtime_error #880

Open
@tropappar

Description

@tropappar

Describe the bug

When I include a custom subtree (called MyTree in this example) from an XML file, it does not work when I specify my root tree inline as string. It throws the following error:

terminate called after throwing an instance of 'std::runtime_error'
what():  Can't find a tree with name: MyTree

However, when I create that same subtree directly or when I include it in another tree that I load from an XML file, everything works fine.

How to Reproduce

This fails:

#include <behaviortree_cpp/bt_factory.h>

int main(int argc, char ** argv)
{
  BT::BehaviorTreeFactory factory;
  factory.registerBehaviorTreeFromFile("/path/to/my_tree.xml");
  std::string tree_xml =
    R"(
    <root BTCPP_format="4" >
        <BehaviorTree ID="TestTree">
            <SubTree ID="MyTree"/>
        </BehaviorTree>
    </root>)";
  auto tree = factory.createTreeFromText(tree_xml);
  auto status = tree.tickWhileRunning();
  return 0;
}

This works:

#include <behaviortree_cpp/bt_factory.h>

int main(int argc, char ** argv)
{
  BT::BehaviorTreeFactory factory;
  factory.registerBehaviorTreeFromFile("/path/to/my_tree.xml");
  auto tree = factory.createTree("MyTree");
  auto status = tree.tickWhileRunning();
  return 0;
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions