Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tropappar opened this issue Oct 30, 2024 · 2 comments
Open

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

tropappar opened this issue Oct 30, 2024 · 2 comments
Assignees
Labels
bug Something isn't working

Comments

@tropappar
Copy link

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;
}
@Aglargil
Copy link
Contributor

Aglargil commented Nov 1, 2024

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:当我从 XML 文件中包含自定义子树(在本示例中称为MyTree )时,当我将根树内联指定为字符串时,它不起作用。它抛出以下错误:

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.但是,当我直接创建相同的子树或将其包含在从 XML 文件加载的另一棵树中时,一切正常。

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;
}

It looks like it's because you didn't define SubTree, I tried to use your second way and still got the error, can you provide the /path/to/my_tree.xml?

@facontidavide facontidavide self-assigned this Nov 1, 2024
@facontidavide facontidavide added the bug Something isn't working label Nov 1, 2024
@tropappar
Copy link
Author

It looks like it's because you didn't define SubTree, I tried to use your second way and still got the error, can you provide the /path/to/my_tree.xml?

Obviously this is a toy example. A definition of MyTree could look like this:

<?xml version="1.0" encoding="UTF-8"?>
<root BTCPP_format="4">
  <BehaviorTree ID="MyTree">
    <AlwaysSuccess/>
  </BehaviorTree>
</root>
``

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants