From ff5bae8d0eee29dc97e267f3f57edb846bdedd7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Sun, 3 Apr 2022 11:03:35 +0200 Subject: [PATCH] Fix crash when passing null to AudioStreamPlayer::set_stream() --- scene/2d/audio_stream_player_2d.cpp | 5 ++++- scene/3d/audio_stream_player_3d.cpp | 5 ++++- scene/audio/audio_stream_player.cpp | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index ac6adf8f5..46173f5bc 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -276,7 +276,10 @@ void AudioStreamPlayer2D::_notification(int p_what) { void AudioStreamPlayer2D::set_stream(Ref p_stream) { // Instancing audio streams can cause large memory allocations, do it prior to AudioServer::lock. - Ref pre_instanced_playback = p_stream->instance_playback(); + Ref pre_instanced_playback; + if (p_stream.is_valid()) { + pre_instanced_playback = p_stream->instance_playback(); + } AudioServer::get_singleton()->lock(); diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index 7d869c2c5..d012387a0 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -628,7 +628,10 @@ void AudioStreamPlayer3D::_notification(int p_what) { void AudioStreamPlayer3D::set_stream(Ref p_stream) { // Instancing audio streams can cause large memory allocations, do it prior to AudioServer::lock. - Ref pre_instanced_playback = p_stream->instance_playback(); + Ref pre_instanced_playback; + if (p_stream.is_valid()) { + pre_instanced_playback = p_stream->instance_playback(); + } AudioServer::get_singleton()->lock(); diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp index 21c620b4b..c4e9895e6 100644 --- a/scene/audio/audio_stream_player.cpp +++ b/scene/audio/audio_stream_player.cpp @@ -168,7 +168,10 @@ void AudioStreamPlayer::_notification(int p_what) { void AudioStreamPlayer::set_stream(Ref p_stream) { // Instancing audio streams can cause large memory allocations, do it prior to AudioServer::lock. - Ref pre_instanced_playback = p_stream->instance_playback(); + Ref pre_instanced_playback; + if (p_stream.is_valid()) { + pre_instanced_playback = p_stream->instance_playback(); + } AudioServer::get_singleton()->lock();