diff --git a/crates/renderer/src/device.rs b/crates/renderer/src/device.rs index e110677..c1fad2b 100644 --- a/crates/renderer/src/device.rs +++ b/crates/renderer/src/device.rs @@ -481,6 +481,16 @@ impl core::ops::Deref for Device { } } +impl AsRef for Device +where + T: ?Sized, + ::Target: AsRef, +{ + fn as_ref(&self) -> &T { + self.deref().as_ref() + } +} + impl DeviceInner { pub fn sync_threadpool(&self) -> &sync::SyncThreadpool { &self.sync_threadpool @@ -749,6 +759,8 @@ impl Drop for DeviceObject { } pub trait DeviceHandle { + /// # Safety + /// The caller must ensure this function is only called once for a given object. unsafe fn destroy(&mut self, device: &Device); } @@ -779,11 +791,9 @@ impl DeviceHandle for vk::Buffer { impl DeviceHandle for vk::SwapchainKHR { unsafe fn destroy(&mut self, device: &Device) { unsafe { - device - .device_extensions - .swapchain - .as_ref() - .map(|swapchain| swapchain.destroy_swapchain(*self, None)); + if let Some(swapchain) = device.device_extensions.swapchain.as_ref() { + swapchain.destroy_swapchain(*self, None) + } } } }