1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-29 16:16:38 +00:00

Merge pull request #54366 from lyuma/audio_stream_player_finished_signal

Fix crash due to reentrancy in AudioStreamPlayer* finished signal.
This commit is contained in:
Rémi Verschelde
2021-10-29 07:53:59 +02:00
committed by GitHub
3 changed files with 9 additions and 3 deletions

View File

@@ -78,7 +78,6 @@ void AudioStreamPlayer2D::_notification(int p_what) {
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove; Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) { for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) { if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
emit_signal(SNAME("finished"));
playbacks_to_remove.push_back(playback); playbacks_to_remove.push_back(playback);
} }
} }
@@ -91,6 +90,9 @@ void AudioStreamPlayer2D::_notification(int p_what) {
active.clear(); active.clear();
set_physics_process_internal(false); set_physics_process_internal(false);
} }
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
} }
while (stream_playbacks.size() > max_polyphony) { while (stream_playbacks.size() > max_polyphony) {

View File

@@ -292,7 +292,6 @@ void AudioStreamPlayer3D::_notification(int p_what) {
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove; Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) { for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) { if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
emit_signal(SNAME("finished"));
playbacks_to_remove.push_back(playback); playbacks_to_remove.push_back(playback);
} }
} }
@@ -305,6 +304,9 @@ void AudioStreamPlayer3D::_notification(int p_what) {
active.clear(); active.clear();
set_physics_process_internal(false); set_physics_process_internal(false);
} }
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
} }
while (stream_playbacks.size() > max_polyphony) { while (stream_playbacks.size() > max_polyphony) {

View File

@@ -45,7 +45,6 @@ void AudioStreamPlayer::_notification(int p_what) {
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove; Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) { for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) { if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
emit_signal(SNAME("finished"));
playbacks_to_remove.push_back(playback); playbacks_to_remove.push_back(playback);
} }
} }
@@ -58,6 +57,9 @@ void AudioStreamPlayer::_notification(int p_what) {
active.clear(); active.clear();
set_process_internal(false); set_process_internal(false);
} }
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
} }
if (p_what == NOTIFICATION_EXIT_TREE) { if (p_what == NOTIFICATION_EXIT_TREE) {