diff --git a/crates/thindx-xaudio2/src/xa28/ixaudio2sourcevoice_ext.rs b/crates/thindx-xaudio2/src/xa28/ixaudio2sourcevoice_ext.rs index 3a46057..13ef49f 100644 --- a/crates/thindx-xaudio2/src/xa28/ixaudio2sourcevoice_ext.rs +++ b/crates/thindx-xaudio2/src/xa28/ixaudio2sourcevoice_ext.rs @@ -56,22 +56,7 @@ impl IXAudio2SourceVoiceTyped { context, - audio_len: audio_data.len(), - audio_data: { - // ⚠️ WARNING: easy to muck up provenance of ArcInner<[Sample]> here. - let raw : *const [Sample] = Arc::into_raw(audio_data); - let raw : *const Sample = unsafe { (*raw).as_ptr() }; - raw.cast() - }, - audio_free: |data, len| { - // 🐞 BUG: core::slice::from_raw_parts here incorrectly narrows provenance from ArcInner<[Sample]> to [Sample] here. - // However, core::ptr::from_raw_parts is not yet stable: https://github.com/rust-lang/rust/issues/81513 - // Local tracking issue: https://github.com/MaulingMonkey/thindx-xaudio2/issues/18 - let audio_data : *const [Sample] = unsafe { core::slice::from_raw_parts(data as *const Sample, len) }; - - let audio_data = unsafe { Arc::from_raw(audio_data) }; - drop(audio_data); - }, + _audio_data: Box::new(audio_data), })).cast(); unsafe { self.SubmitSourceBuffer(&b, null()) }.succeeded() diff --git a/crates/thindx-xaudio2/src/xa28/source_buffer.rs b/crates/thindx-xaudio2/src/xa28/source_buffer.rs index 4daab66..dd459c6 100644 --- a/crates/thindx-xaudio2/src/xa28/source_buffer.rs +++ b/crates/thindx-xaudio2/src/xa28/source_buffer.rs @@ -1,6 +1,6 @@ #[allow(unused_imports)] use super::*; #[allow(unused_imports)] use super::xaudio2::sys::*; -use core::ffi::c_void; +use std::any::Any; @@ -10,7 +10,5 @@ use core::ffi::c_void; /// * [VoiceCallback::BufferContext] parameters pub(crate) struct SourceBuffer { pub(crate) context: Context, - pub(crate) audio_data: *const c_void, - pub(crate) audio_len: usize, - pub(crate) audio_free: unsafe fn(*const c_void, usize), + pub(crate) _audio_data: Box, // for keepalive only } diff --git a/crates/thindx-xaudio2/src/xa28/voice_callback.rs b/crates/thindx-xaudio2/src/xa28/voice_callback.rs index d07b15a..0441806 100644 --- a/crates/thindx-xaudio2/src/xa28/voice_callback.rs +++ b/crates/thindx-xaudio2/src/xa28/voice_callback.rs @@ -118,7 +118,6 @@ impl VoiceCallbackWrapper { let this : &Self = unsafe { &*sptr::from_exposed_addr(sptr::Strict::addr(this)) }; let buffer_context = *unsafe { Box::from_raw(buffer_context as *mut SourceBuffer) }; this.callbacks.on_buffer_end(buffer_context.context); - unsafe { (buffer_context.audio_free)(buffer_context.audio_data, buffer_context.audio_len) } }) }