From 3680cfde86997631388b272f27001b4b559b25f2 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() (cherry picked from commit 9e2d5120c1b8d53f91d8ff87b917c3e36f6e6d91) --- 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 48507e0532b..5dc61439a38 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -272,7 +272,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 e0e86ece401..31cd574950f 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -623,7 +623,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 f3ecb8aa4ca..4b389aab22b 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();