Merge pull request #59829 from RandomShaper/fix_null_stream_crash_3.x

[3.x] Fix crash when passing null to AudioStreamPlayer::set_stream()
This commit is contained in:
Ellen Poe 2022-04-03 05:40:54 -07:00 committed by GitHub
commit a5f9e1ce18
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 3 deletions

View file

@ -272,7 +272,10 @@ void AudioStreamPlayer2D::_notification(int p_what) {
void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) {
// Instancing audio streams can cause large memory allocations, do it prior to AudioServer::lock.
Ref<AudioStreamPlayback> pre_instanced_playback = p_stream->instance_playback();
Ref<AudioStreamPlayback> pre_instanced_playback;
if (p_stream.is_valid()) {
pre_instanced_playback = p_stream->instance_playback();
}
AudioServer::get_singleton()->lock();

View file

@ -623,7 +623,10 @@ void AudioStreamPlayer3D::_notification(int p_what) {
void AudioStreamPlayer3D::set_stream(Ref<AudioStream> p_stream) {
// Instancing audio streams can cause large memory allocations, do it prior to AudioServer::lock.
Ref<AudioStreamPlayback> pre_instanced_playback = p_stream->instance_playback();
Ref<AudioStreamPlayback> pre_instanced_playback;
if (p_stream.is_valid()) {
pre_instanced_playback = p_stream->instance_playback();
}
AudioServer::get_singleton()->lock();

View file

@ -168,7 +168,10 @@ void AudioStreamPlayer::_notification(int p_what) {
void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) {
// Instancing audio streams can cause large memory allocations, do it prior to AudioServer::lock.
Ref<AudioStreamPlayback> pre_instanced_playback = p_stream->instance_playback();
Ref<AudioStreamPlayback> pre_instanced_playback;
if (p_stream.is_valid()) {
pre_instanced_playback = p_stream->instance_playback();
}
AudioServer::get_singleton()->lock();