Skip to content

Initialize all instances of std::atomic_bool #772

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 13, 2024

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