Skip to content

Scripts don't work: Encoding issue? #1131

Open

Description

@tropappar

Describe the bug

The script action node always crashes:

[my_bt_node] terminate called after throwing an instance of 'BT::RuntimeError'
[my_bt_node]   what():  Invalid token '�' at position 1

Stacktrace:

__pthread_kill_implementation@0x00007f32e80c4b2c (./nptl/pthread_kill.c:44)
__pthread_kill_internal@0x00007f32e80c4b2c (./nptl/pthread_kill.c:78)
__GI___pthread_kill@0x00007f32e80c4b2c (./nptl/pthread_kill.c:89)
__GI_raise@0x00007f32e806b27e (../sysdeps/posix/raise.c:26)
__GI_abort@0x00007f32e804e8ff (./stdlib/abort.c:79)
??@0x00007f32e82ddff5 (Unknown Source:0)
??@0x00007f32e82f30da (Unknown Source:0)
std::terminate()@0x00007f32e82dda55 (Unknown Source:0)
__cxa_throw@0x00007f32e82f3391 (Unknown Source:0)
??@0x00007f32e87208c9 (Unknown Source:0)
std::_Function_handler<std::unique_ptr<BT::TreeNode, std::default_delete<BT::TreeNode> > (std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, BT::NodeConfig const&), BT::CreateBuilder<BT::ScriptNode>()::{lambda(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, BT::NodeConfig const&)#1}>::_M_invoke(std::_Any_data const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, BT::NodeConfig const&)@0x00007f32e8772705 (Unknown Source:0)
BT::BehaviorTreeFactory::instantiateTreeNode(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, BT::NodeConfig const&) const@0x00007f32e8761bef (Unknown Source:0)
BT::XMLParser::PImpl::createNodeFromXML(tinyxml2::XMLElement const*, std::shared_ptr<BT::Blackboard> const&, std::shared_ptr<BT::TreeNode> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, BT::Tree&)@0x00007f32e879e00f (Unknown Source:0)
??@0x00007f32e879f22e (Unknown Source:0)
??@0x00007f32e87a0396 (Unknown Source:0)
BT::XMLParser::PImpl::recursivelyCreateSubtree(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, BT::Tree&, std::shared_ptr<BT::Blackboard>, std::shared_ptr<BT::TreeNode> const&, std::unordered_set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&)@0x00007f32e87988e3 (Unknown Source:0)
BT::XMLParser::instantiateTree(std::shared_ptr<BT::Blackboard> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >)@0x00007f32e879cd17 (Unknown Source:0)
BT::BehaviorTreeFactory::createTree(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::shared_ptr<BT::Blackboard>)@0x00007f32e875c69b (Unknown Source:0)
my_bt_node::MyBtNode::run_tree@0x0000561bb07d0982 ([...]/my_bt_node.cpp:57)
main@0x0000561bb07d00f0 ([...]/my_main.cpp:27)

How to Reproduce

  std::string tree_text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                          "<root BTCPP_format=\"4\">\n"
                          "  <BehaviorTree ID=\"Pi\">\n"
                          "    <Script code=\"pi:=3.14\"/>\n"
                          "  </BehaviorTree>\n"
                          "  <!-- Description of Node Models (used by Groot) -->\n"
                          "  <TreeNodesModel/>\n"
                          "</root>";
  factory.registerBehaviorTreeFromText(tree_text);
  auto tree = factory.createTree("Pi");
  tree.tickWhileRunning();

Activity

  1. webzuweb commented on Sep 23, 2026

    @webzuweb
    Contributor

    I can't reproduce this on current master with the exact snippet — pi:=3.14 tokenizes cleanly as Identifier(pi) ColonEqual Real(3.14). The hand-written tokenizer (PR #1099, merged 2026-02-04) supports := as the assignment operator, and tests/script_parser_test.cpp has dozens of passing := cases (e.g. x:= 3; y:=5; x+y).

    The token � (U+FFFD) at position 1 strongly suggests the actual bytes fed to the Script node aren't valid UTF-8 — the most common cause is a UTF-8 BOM (EF BB BF) at the start of the file/string, or an XML file saved in a non-UTF-8 encoding (e.g. UTF-16 or Windows-1252). The in-memory std::string in the repro is pure ASCII, so it can't produce that by itself.

    Could you share the exact XML file (or its first bytes / encoding) that triggered the crash? If there's a BOM or non-UTF-8 byte sequence in the code attribute, that would pinpoint whether this is a parser robustness gap worth fixing (e.g. stripping a leading BOM) versus an input-encoding issue.

  2. facontidavide commented on Oct 24, 2026

    @facontidavide
    Collaborator

    We can't reproduce this from the snippet: pi:=3.14 tokenizes correctly. The � in the error is a single byte of a multi-byte character, which points to a non-ASCII character in the real script (a BOM, a non-breaking space, or a Unicode lookalike such as :), while script identifiers are ASCII-only. Could you attach the exact XML file, or the output of xxd on the attribute value? Without that we'll close this in about two weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions