From 878649aa6603becb3d19a9583b549985aac2ce29 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Wed, 20 Sep 2023 17:14:43 -0400 Subject: [PATCH] WIP: fix: avoid `mut_void` for D3D12 debug layer init. --- d3d12/src/com.rs | 12 +++++++----- d3d12/src/debug.rs | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/d3d12/src/com.rs b/d3d12/src/com.rs index f0eca926fe3..63454ae46f6 100644 --- a/d3d12/src/com.rs +++ b/d3d12/src/com.rs @@ -16,6 +16,10 @@ impl ComPtr { ComPtr(ptr::null_mut()) } + pub unsafe fn from_reffed(raw: *mut T) -> Self { + ComPtr(raw) + } + /// Create a ComPtr from a raw pointer. This will call AddRef on the pointer. /// /// # Safety @@ -100,11 +104,9 @@ impl ComPtr { U: Interface, { debug_assert!(!self.is_null()); - let mut obj = ComPtr::::null(); - let hr = self - .as_unknown() - .QueryInterface(&U::uuidof(), obj.mut_void()); - (obj, hr) + let mut obj = std::ptr::null_mut(); + let hr = self.as_unknown().QueryInterface(&U::uuidof(), &mut obj); + (ComPtr::from_reffed(obj.cast()), hr) } } diff --git a/d3d12/src/debug.rs b/d3d12/src/debug.rs index 3a6abc46b7e..ec344f0be4b 100644 --- a/d3d12/src/debug.rs +++ b/d3d12/src/debug.rs @@ -13,11 +13,12 @@ impl crate::D3D12Lib { *mut *mut winapi::ctypes::c_void, ) -> crate::HRESULT; - let mut debug = Debug::null(); + let mut debug = std::ptr::null_mut(); let hr = unsafe { let func: libloading::Symbol = self.lib.get(b"D3D12GetDebugInterface")?; - func(&d3d12sdklayers::ID3D12Debug::uuidof(), debug.mut_void()) + func(&d3d12sdklayers::ID3D12Debug::uuidof(), &mut debug) }; + let debug = unsafe { ComPtr::from_reffed(debug.cast()) }; Ok((debug, hr)) }