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();