Fix process mode update when mode owner is set to Inherit

Prevent the root node to be set to PROCESS_MODE_INHERIT, since it causes
undefined behavior.

Fix a case where the process owner node is wrongly set to the direct
parent instead of the proper node.

Add errors for all unhandled cases.
This commit is contained in:
PouleyKetchoupp 2021-06-21 17:49:34 -07:00
parent 29bdd000f0
commit 226d6337e5
2 changed files with 12 additions and 6 deletions

View File

@ -70,7 +70,9 @@ void Node::_notification(int p_notification) {
if (data.parent) {
data.process_owner = data.parent->data.process_owner;
} else {
data.process_owner = nullptr;
ERR_PRINT("The root node can't be set to Inherit process mode, reverting to Pausable instead.");
data.process_mode = PROCESS_MODE_PAUSABLE;
data.process_owner = this;
}
} else {
data.process_owner = this;
@ -437,18 +439,18 @@ void Node::set_process_mode(ProcessMode p_mode) {
bool prev_can_process = can_process();
bool prev_enabled = _is_enabled();
data.process_mode = p_mode;
if (data.process_mode == PROCESS_MODE_INHERIT) {
if (p_mode == PROCESS_MODE_INHERIT) {
if (data.parent) {
data.process_owner = data.parent->data.owner;
data.process_owner = data.parent->data.process_owner;
} else {
data.process_owner = nullptr;
ERR_FAIL_MSG("The root node can't be set to Inherit process mode.");
}
} else {
data.process_owner = this;
}
data.process_mode = p_mode;
bool next_can_process = can_process();
bool next_enabled = _is_enabled();
@ -703,6 +705,9 @@ bool Node::_can_process(bool p_paused) const {
process_mode = data.process_mode;
}
// The owner can't be set to inherit, must be a bug.
ERR_FAIL_COND_V(process_mode == PROCESS_MODE_INHERIT, false);
if (process_mode == PROCESS_MODE_DISABLED) {
return false;
} else if (process_mode == PROCESS_MODE_ALWAYS) {

View File

@ -1331,6 +1331,7 @@ SceneTree::SceneTree() {
// Create with mainloop.
root = memnew(Window);
root->set_process_mode(Node::PROCESS_MODE_PAUSABLE);
root->set_name("root");
#ifndef _3D_DISABLED
if (!root->get_world_3d().is_valid()) {