From 70e08dd8831b622aba8896c98da6499635e8c53f Mon Sep 17 00:00:00 2001 From: Serkyo Date: Thu, 30 Apr 2026 14:26:18 +0200 Subject: [PATCH] feat(renderer): implement Drop trait for resource cleanup Ensured that the Logical Device, Debug Messenger, and Instance are destroyed in the correct reverse order when the Renderer is dropped. Added documentation for the cleanup process. --- crates/renderer/src/lib.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/renderer/src/lib.rs b/crates/renderer/src/lib.rs index 8e437ae..8785a83 100644 --- a/crates/renderer/src/lib.rs +++ b/crates/renderer/src/lib.rs @@ -175,6 +175,21 @@ impl Renderer { } } +/// Ensures all Vulkan resources are destroyed in the correct order. +impl Drop for Renderer { + fn drop(&mut self) { + unsafe { + self.device.destroy_device(None); + + if let Some(utils) = &self.debug_utils { + utils.destroy_debug_utils_messenger(self.debug_messenger, None); + } + + self.instance.destroy_instance(None); + } + } +} + /// The callback function invoked by Vulkan's validation layers. /// /// This function translates Vulkan debug messages into `tracing` events.