splintered-reality / py_trees

Python implementation of behaviour trees.
Other
433 stars 143 forks source link

Replacing a child of a Sequence with memory=True causes AssertionError #421

Open nikola-j opened 1 year ago

nikola-j commented 1 year ago

Calling replace_child will call remove_child which will set the current_child to None.

This will cause an assertation error next time the Sequence ticks, when it asserts that the current child is not None

Example traceback

[executor_node-1] Traceback (most recent call last):
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/install/wm_executor/lib/wm_executor/executor_node", line 33, in <module>
[executor_node-1]     sys.exit(load_entry_point('wm-executor', 'console_scripts', 'executor_node')())
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/build/wm_executor/wm_executor/executor_node.py", line 594, in main
[executor_node-1]     executor.spin()
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/install/rclpy/local/lib/python3.10/dist-packages/rclpy/executors.py", line 279, in spin
[executor_node-1]     self.spin_once()
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/install/rclpy/local/lib/python3.10/dist-packages/rclpy/executors.py", line 764, in spin_once
[executor_node-1]     self._spin_once_impl(timeout_sec)
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/install/rclpy/local/lib/python3.10/dist-packages/rclpy/executors.py", line 761, in _spin_once_impl
[executor_node-1]     future.result()
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/install/rclpy/local/lib/python3.10/dist-packages/rclpy/task.py", line 94, in result
[executor_node-1]     raise self.exception()
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/install/rclpy/local/lib/python3.10/dist-packages/rclpy/task.py", line 239, in __call__
[executor_node-1]     self._handler.send(None)
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/install/rclpy/local/lib/python3.10/dist-packages/rclpy/executors.py", line 418, in handler
[executor_node-1]     await call_coroutine(entity, arg)
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/install/rclpy/local/lib/python3.10/dist-packages/rclpy/executors.py", line 332, in _execute_timer
[executor_node-1]     await await_or_execute(tmr.callback)
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/install/rclpy/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
[executor_node-1]     return callback(*args)
[executor_node-1]   File "/home/nikola/Documents/Work/wm_ws/build/py_trees_ros/py_trees_ros/trees.py", line 573, in _tick_tock_timer_callback
[executor_node-1]     self.tick(pre_tick_handler, post_tick_handler)
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/trees.py", line 412, in tick
[executor_node-1]     for node in self.root.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/composites.py", line 714, in tick
[executor_node-1]     for node in child.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/composites.py", line 437, in tick
[executor_node-1]     for node in child.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/decorators.py", line 451, in tick
[executor_node-1]     for node in super().tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/decorators.py", line 129, in tick
[executor_node-1]     for node in self.decorated.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/composites.py", line 560, in tick
[executor_node-1]     for node in child.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/decorators.py", line 129, in tick
[executor_node-1]     for node in self.decorated.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/composites.py", line 560, in tick
[executor_node-1]     for node in child.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/composites.py", line 437, in tick
[executor_node-1]     for node in child.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/composites.py", line 560, in tick
[executor_node-1]     for node in child.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/composites.py", line 437, in tick
[executor_node-1]     for node in child.tick():
[executor_node-1]   File "/home/nikola/.local/lib/python3.10/site-packages/py_trees/composites.py", line 543, in tick
[executor_node-1]     assert self.current_child is not None  # should never be true, help mypy out
[executor_node-1] AssertionError