Skip to content

Conversation

MarqRazz
Copy link
Contributor

@MarqRazz MarqRazz commented Feb 13, 2024

I have been testing a sequence of behaviors based on the StatefulActionNode and noticed that sometimes my behaviors would immediately return because the value of isHaltRequested() was checked in the onRunning() method. After some digging I found that the value halt_requested_ is uninitialized and set to a random value when constructing my StatefulActionNode based objects.

I added a simple print statement to the constructor of StatefulActionNode and this is what I found:

[node_main] StatefulActionNode: halt_requested_ = 0
[node_main] StatefulActionNode: halt_requested_ = 1
[node_main] StatefulActionNode: halt_requested_ = 1
[node_main] StatefulActionNode: halt_requested_ = 0
[node_main] StatefulActionNode: halt_requested_ = 1
[node_main] StatefulActionNode: halt_requested_ = 1
[node_main] StatefulActionNode: halt_requested_ = 0
[node_main] StatefulActionNode: halt_requested_ = 1
[node_main] StatefulActionNode: halt_requested_ = 1
[node_main] StatefulActionNode: halt_requested_ = 1
[node_main] StatefulActionNode: halt_requested_ = 1
[node_main] StatefulActionNode: halt_requested_ = 1
[node_main] : Sequence IDLE -> RUNNING
....

This PR initializes all instances of std::atomic_bool and a handful of bool member variables. I would think it's best practice to initialize all member variables but wanted to push this up and get your thoughts before investing more time.

@facontidavide
Copy link
Collaborator

wow, thanks for finding (and fixing) this

@facontidavide facontidavide merged commit 21ab495 into BehaviorTree:master Feb 13, 2024
@MarqRazz MarqRazz deleted the pr-initialize_bools branch February 14, 2024 15:47
facontidavide pushed a commit that referenced this pull request Feb 16, 2024
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