From 7b2e26e3e6ac7466025261ada55dd33891bcde50 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 20 Sep 2021 09:26:44 -0500 Subject: [PATCH] Add check for swapped buffers, and reset source if needed. --- src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e4d05ba..4ec421d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -315,6 +315,20 @@ fn update_source_properties( .. } = *sound; if state != SoundState::Stopped { + let mut swap_buffers = false; + if let Some(source) = &sound.source { + let source = source.lock().unwrap(); + if let Some(source_buffer) = source.buffer() { + if let Some(sound_buffer) = buffers.0.get(&sound.buffer.id) { + if source_buffer.as_raw() != sound_buffer.as_raw() { + swap_buffers = true; + } + } + } + } + if swap_buffers { + sound.source = None; + } if sound.source.is_none() { if let Ok(mut source) = context.new_static_source() { if let Some(buffer) = buffers.0.get(&sound.buffer.id) {