From 90cf873979a0e5b13a2cbc97eb077ee9266e48a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Fertyk?= Date: Thu, 23 Nov 2023 13:41:05 +0100 Subject: [PATCH] Fix AudioStreamPlayer not paused on pause mode change Fixes #58543. --- scene/main/node.cpp | 36 ++++++++++++++++++++++++------------ scene/main/node.h | 1 + 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/scene/main/node.cpp b/scene/main/node.cpp index e528a4a6723..d73526f54ed 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -517,25 +517,27 @@ void Node::set_pause_mode(PauseMode p_mode) { } bool prev_inherits = data.pause_mode == PAUSE_MODE_INHERIT; + bool prev_can_process = is_inside_tree() && can_process(); data.pause_mode = p_mode; if (!is_inside_tree()) { return; //pointless } - if ((data.pause_mode == PAUSE_MODE_INHERIT) == prev_inherits) { - return; ///nothing changed - } + if ((data.pause_mode == PAUSE_MODE_INHERIT) != prev_inherits) { + Node *owner = nullptr; - Node *owner = nullptr; - - if (data.pause_mode == PAUSE_MODE_INHERIT) { - if (data.parent) { - owner = data.parent->data.pause_owner; + if (data.pause_mode == PAUSE_MODE_INHERIT) { + if (data.parent) { + owner = data.parent->data.pause_owner; + } + } else { + owner = this; } - } else { - owner = this; - } - _propagate_pause_owner(owner); + _propagate_pause_owner(owner); + } + if (prev_can_process != can_process()) { + _propagate_pause_change_notification(can_process() ? NOTIFICATION_UNPAUSED : NOTIFICATION_PAUSED); + } } Node::PauseMode Node::get_pause_mode() const { @@ -552,6 +554,16 @@ void Node::_propagate_pause_owner(Node *p_owner) { } } +void Node::_propagate_pause_change_notification(int p_notification) { + notification(p_notification); + + for (int i = 0; i < data.children.size(); i++) { + if (data.children[i]->data.pause_mode == PAUSE_MODE_INHERIT) { + data.children[i]->_propagate_pause_change_notification(p_notification); + } + } +} + void Node::set_network_master(int p_peer_id, bool p_recursive) { data.network_master = p_peer_id; diff --git a/scene/main/node.h b/scene/main/node.h index 133d01dbfb7..e7c57473efc 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -208,6 +208,7 @@ private: void _print_stray_nodes(); void _propagate_pause_owner(Node *p_owner); void _propagate_groups_dirty(); + void _propagate_pause_change_notification(int p_notification); Array _get_node_and_resource(const NodePath &p_path); void _duplicate_signals(const Node *p_original, Node *p_copy) const;