From 4897227d04f49730cd7e288bd08c98450f6204b2 Mon Sep 17 00:00:00 2001 From: chanon Date: Tue, 19 Jun 2018 18:56:05 +0700 Subject: [PATCH] fix can't set AudioStreamPlayer stream to null (cherry picked from commit 2bdac0a5d90811158c0615ab4d16e5dcff933957) --- scene/2d/audio_stream_player_2d.cpp | 10 +++++----- scene/3d/audio_stream_player_3d.cpp | 10 +++++----- scene/audio/audio_player.cpp | 1 - 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index ef7b7d7512e..86b2f6fc07f 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -241,7 +241,6 @@ void AudioStreamPlayer2D::_notification(int p_what) { void AudioStreamPlayer2D::set_stream(Ref p_stream) { - ERR_FAIL_COND(!p_stream.is_valid()); AudioServer::get_singleton()->lock(); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); @@ -253,14 +252,15 @@ void AudioStreamPlayer2D::set_stream(Ref p_stream) { setseek = -1; } - stream = p_stream; - stream_playback = p_stream->instance_playback(); + if (p_stream.is_valid()) { + stream = p_stream; + stream_playback = p_stream->instance_playback(); + } AudioServer::get_singleton()->unlock(); - if (stream_playback.is_null()) { + if (p_stream.is_valid() && stream_playback.is_null()) { stream.unref(); - ERR_FAIL_COND(stream_playback.is_null()); } } diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index fa2b7987699..f838d34bb9a 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -551,7 +551,6 @@ void AudioStreamPlayer3D::_notification(int p_what) { void AudioStreamPlayer3D::set_stream(Ref p_stream) { - ERR_FAIL_COND(!p_stream.is_valid()); AudioServer::get_singleton()->lock(); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); @@ -563,14 +562,15 @@ void AudioStreamPlayer3D::set_stream(Ref p_stream) { setseek = -1; } - stream = p_stream; - stream_playback = p_stream->instance_playback(); + if (p_stream.is_valid()) { + stream = p_stream; + stream_playback = p_stream->instance_playback(); + } AudioServer::get_singleton()->unlock(); - if (stream_playback.is_null()) { + if (p_stream.is_valid() && stream_playback.is_null()) { stream.unref(); - ERR_FAIL_COND(stream_playback.is_null()); } } diff --git a/scene/audio/audio_player.cpp b/scene/audio/audio_player.cpp index e7ace82fc02..401dfd81596 100644 --- a/scene/audio/audio_player.cpp +++ b/scene/audio/audio_player.cpp @@ -160,7 +160,6 @@ void AudioStreamPlayer::set_stream(Ref p_stream) { if (p_stream.is_valid() && stream_playback.is_null()) { stream.unref(); - ERR_FAIL_COND(stream_playback.is_null()); } }