fix can't set AudioStreamPlayer stream to null

(cherry picked from commit 2bdac0a5d9)
This commit is contained in:
chanon 2018-06-19 18:56:05 +07:00 committed by Hein-Pieter van Braam
parent 11cbf850a4
commit 4897227d04
3 changed files with 10 additions and 11 deletions

View File

@ -241,7 +241,6 @@ void AudioStreamPlayer2D::_notification(int p_what) {
void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) { void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) {
ERR_FAIL_COND(!p_stream.is_valid());
AudioServer::get_singleton()->lock(); AudioServer::get_singleton()->lock();
mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size());
@ -253,14 +252,15 @@ void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) {
setseek = -1; setseek = -1;
} }
if (p_stream.is_valid()) {
stream = p_stream; stream = p_stream;
stream_playback = p_stream->instance_playback(); stream_playback = p_stream->instance_playback();
}
AudioServer::get_singleton()->unlock(); AudioServer::get_singleton()->unlock();
if (stream_playback.is_null()) { if (p_stream.is_valid() && stream_playback.is_null()) {
stream.unref(); stream.unref();
ERR_FAIL_COND(stream_playback.is_null());
} }
} }

View File

@ -551,7 +551,6 @@ void AudioStreamPlayer3D::_notification(int p_what) {
void AudioStreamPlayer3D::set_stream(Ref<AudioStream> p_stream) { void AudioStreamPlayer3D::set_stream(Ref<AudioStream> p_stream) {
ERR_FAIL_COND(!p_stream.is_valid());
AudioServer::get_singleton()->lock(); AudioServer::get_singleton()->lock();
mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size()); mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size());
@ -563,14 +562,15 @@ void AudioStreamPlayer3D::set_stream(Ref<AudioStream> p_stream) {
setseek = -1; setseek = -1;
} }
if (p_stream.is_valid()) {
stream = p_stream; stream = p_stream;
stream_playback = p_stream->instance_playback(); stream_playback = p_stream->instance_playback();
}
AudioServer::get_singleton()->unlock(); AudioServer::get_singleton()->unlock();
if (stream_playback.is_null()) { if (p_stream.is_valid() && stream_playback.is_null()) {
stream.unref(); stream.unref();
ERR_FAIL_COND(stream_playback.is_null());
} }
} }

View File

@ -160,7 +160,6 @@ void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) {
if (p_stream.is_valid() && stream_playback.is_null()) { if (p_stream.is_valid() && stream_playback.is_null()) {
stream.unref(); stream.unref();
ERR_FAIL_COND(stream_playback.is_null());
} }
} }