From f04912df704963fdf35b3b33a94c50b0e3d39061 Mon Sep 17 00:00:00 2001 From: Serkyo Date: Sat, 16 May 2026 19:43:16 +0200 Subject: [PATCH] fix(renderer): plug shader-module and stale-handle leaks create_graphics_pipeline now destroys its shader modules on the error path as well, and update_mesh nulls the buffer handles after destroying them so a later Drop or retry cannot redestroy freed buffers. --- crates/renderer/src/pipeline.rs | 10 ++++------ crates/renderer/src/renderer.rs | 2 ++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/renderer/src/pipeline.rs b/crates/renderer/src/pipeline.rs index 3c3130e..5c49fa1 100644 --- a/crates/renderer/src/pipeline.rs +++ b/crates/renderer/src/pipeline.rs @@ -135,18 +135,16 @@ pub fn create_graphics_pipeline( .layout(layout) .depth_stencil_state(depth_stencil_state); - let pipeline = unsafe { - device - .create_graphics_pipelines(vk::PipelineCache::null(), &[pipeline_info], None) - .map_err(|(_, e)| e)? - }[0]; + let result = unsafe { + device.create_graphics_pipelines(vk::PipelineCache::null(), &[pipeline_info], None) + }; - // Cleanup temporary shader modules (they are baked into the pipeline now) unsafe { device.destroy_shader_module(vert_module, None); device.destroy_shader_module(frag_module, None); } + let pipeline = result.map_err(|(_, e)| e)?[0]; Ok(pipeline) } diff --git a/crates/renderer/src/renderer.rs b/crates/renderer/src/renderer.rs index 80e5048..0b459b4 100644 --- a/crates/renderer/src/renderer.rs +++ b/crates/renderer/src/renderer.rs @@ -369,11 +369,13 @@ impl Renderer { let _ = allocator.free(alloc); } self.device.destroy_buffer(self.vertex_buffer, None); + self.vertex_buffer = vk::Buffer::null(); if let Some(alloc) = self.index_allocation.take() { let _ = allocator.free(alloc); } self.device.destroy_buffer(self.index_buffer, None); + self.index_buffer = vk::Buffer::null(); } let allocator = self