Skip to content

Conversation

@nandojve
Copy link
Contributor

@nandojve nandojve commented Jan 1, 2026

This tries to fix the issue with the usage of subtrees.

When a subtree was used multiple times in a behavior tree, the
generator produced incorrect sibling/child indices because it
reused the same XML element IDs for all instances. This caused
getIndexedNode() to always return the first instance's entry.

The fix expands subtrees by creating deep copies of their content
before processing, ensuring each instance has unique element IDs.

Fixes: #28
Signed-off-by: Gerson Fernando Budke <[email protected]>
Add a sample that validates correct behavior tree traversal when a
subtree is used multiple times. This reproduces the scenario from
issue #28 where incorrect indices caused nodes to be skipped during
execution.

The behavior tree structure tests:
  Sequence -> SubTree(sub) -> A -> SubTree(sub) -> B

Expected execution order: sub -> A -> sub -> B

The test verifies that all nodes are evaluated in the correct order
and that no nodes are skipped due to incorrect sibling indices.

Signed-off-by: Gerson Fernando Budke <[email protected]>
@nandojve nandojve merged commit 6c3680d into master Jan 6, 2026
3 checks passed
@nandojve nandojve deleted the fix_subtree_reuse branch January 6, 2026 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect traversal when a subtree is used multiple times

3 participants