diff options
author | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-06-21 17:49:34 -0700 |
---|---|---|
committer | PouleyKetchoupp <pouleyketchoup@gmail.com> | 2021-09-06 17:14:12 -0700 |
commit | 226d6337e5b6f119c4519da15877708cb026a02d (patch) | |
tree | 8f02a90c25f50036d648949c142b50126cf7dc20 | |
parent | 29bdd000f0e59b8076929f7f05f06059d3d16fef (diff) |
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.
-rw-r--r-- | scene/main/node.cpp | 17 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 1 |
2 files changed, 12 insertions, 6 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp index f2a2648140..b783a4b770 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -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) { diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 8260d0dff5..f0e39c0768 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -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()) { |