Skip to content

Commit

Permalink
Merge pull request #58577 from pfertyk/issue_58543_audio_not_paused
Browse files Browse the repository at this point in the history
[3.x] Fix AudioStreamPlayer not paused on pause mode change
  • Loading branch information
lawnjelly authored Apr 20, 2024
2 parents 9401e18 + 90cf873 commit a73715c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
36 changes: 24 additions & 12 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,25 +516,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
}

Node *owner = nullptr;
if ((data.pause_mode == PAUSE_MODE_INHERIT) != prev_inherits) {
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 {
Expand All @@ -551,6 +553,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;

Expand Down
1 change: 1 addition & 0 deletions scene/main/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ class Node : public Object {
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;
Expand Down

0 comments on commit a73715c

Please sign in to comment.