Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] instance audio streams before AudioServer::lock call #59413

Merged
merged 1 commit into from
Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion scene/2d/audio_stream_player_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ 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();

AudioServer::get_singleton()->lock();

mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size());
Expand All @@ -284,7 +287,7 @@ void AudioStreamPlayer2D::set_stream(Ref<AudioStream> p_stream) {

if (p_stream.is_valid()) {
stream = p_stream;
stream_playback = p_stream->instance_playback();
stream_playback = pre_instanced_playback;
}

AudioServer::get_singleton()->unlock();
Expand Down
5 changes: 4 additions & 1 deletion scene/3d/audio_stream_player_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,9 @@ 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();

AudioServer::get_singleton()->lock();

mix_buffer.resize(AudioServer::get_singleton()->thread_get_mix_buffer_size());
Expand All @@ -635,7 +638,7 @@ void AudioStreamPlayer3D::set_stream(Ref<AudioStream> p_stream) {

if (p_stream.is_valid()) {
stream = p_stream;
stream_playback = p_stream->instance_playback();
stream_playback = pre_instanced_playback;
}

AudioServer::get_singleton()->unlock();
Expand Down
5 changes: 4 additions & 1 deletion scene/audio/audio_stream_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ 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();

AudioServer::get_singleton()->lock();

if (active.is_set() && stream_playback.is_valid() && !stream_paused) {
Expand Down Expand Up @@ -203,7 +206,7 @@ void AudioStreamPlayer::set_stream(Ref<AudioStream> p_stream) {

if (p_stream.is_valid()) {
stream = p_stream;
stream_playback = p_stream->instance_playback();
stream_playback = pre_instanced_playback;
}

AudioServer::get_singleton()->unlock();
Expand Down