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.
This commit is contained in:
Serkyo 2026-05-16 19:43:16 +02:00
parent 4130ebf5f9
commit f04912df70
2 changed files with 6 additions and 6 deletions

View file

@ -135,18 +135,16 @@ pub fn create_graphics_pipeline(
.layout(layout) .layout(layout)
.depth_stencil_state(depth_stencil_state); .depth_stencil_state(depth_stencil_state);
let pipeline = unsafe { let result = unsafe {
device device.create_graphics_pipelines(vk::PipelineCache::null(), &[pipeline_info], None)
.create_graphics_pipelines(vk::PipelineCache::null(), &[pipeline_info], None) };
.map_err(|(_, e)| e)?
}[0];
// Cleanup temporary shader modules (they are baked into the pipeline now)
unsafe { unsafe {
device.destroy_shader_module(vert_module, None); device.destroy_shader_module(vert_module, None);
device.destroy_shader_module(frag_module, None); device.destroy_shader_module(frag_module, None);
} }
let pipeline = result.map_err(|(_, e)| e)?[0];
Ok(pipeline) Ok(pipeline)
} }

View file

@ -369,11 +369,13 @@ impl Renderer {
let _ = allocator.free(alloc); let _ = allocator.free(alloc);
} }
self.device.destroy_buffer(self.vertex_buffer, None); self.device.destroy_buffer(self.vertex_buffer, None);
self.vertex_buffer = vk::Buffer::null();
if let Some(alloc) = self.index_allocation.take() { if let Some(alloc) = self.index_allocation.take() {
let _ = allocator.free(alloc); let _ = allocator.free(alloc);
} }
self.device.destroy_buffer(self.index_buffer, None); self.device.destroy_buffer(self.index_buffer, None);
self.index_buffer = vk::Buffer::null();
} }
let allocator = self let allocator = self