Skip to content

match subtrees by name in ImportTreeFromJSON - #1227

Merged
facontidavide merged 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:import-tree-json-by-name
Oct 10, 2026
Merged

facontidavide merged 1 commit into
BehaviorTree:masterfrom
aysha-afrah26:import-tree-json-by-name

Conversation

@aysha-afrah26

Copy link
Copy Markdown
Contributor

Export/import round trip on current master, from the regression test added here:

tests/gtest_blackboard.cpp:782: Failure
Expected equality of these values:
  blackboard->get<std::string>("owner")
    Which is: "alpha"
  expected_owner[i]
    Which is: "main"

ImportTreeFromJSON writes the n-th JSON object into tree.subtrees[n], but ExportTreeToJSON keys the document by subtree name and nlohmann::json iterates keys alphabetically, so the blackboards are restored into the wrong subtrees unless the names happen to sort in creation order (Sub::10 already sorts before Sub::9). Each subtree is now looked up by the name the exporter writes; a document missing one of them throws std::runtime_error where it used to be applied by position.

ExportTreeToJSON keys the document by subtree name and nlohmann::json iterates keys in alphabetical order, so pairing the n-th object with tree.subtrees[n] restored each blackboard into a different subtree. Look every subtree up by name instead.
@facontidavide
facontidavide merged commit afa1bce into BehaviorTree:master Oct 10, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants