diff --git a/crates/yakui-vulkan/src/lib.rs b/crates/yakui-vulkan/src/lib.rs index 654f7ef5..4f3a67cb 100644 --- a/crates/yakui-vulkan/src/lib.rs +++ b/crates/yakui-vulkan/src/lib.rs @@ -598,7 +598,9 @@ impl YakuiVulkan { TextureChange::Removed => { if let Some(removed) = self.yakui_managed_textures.remove(&id) { - unsafe { removed.cleanup(vulkan_context.device) }; + unsafe { + self.uploads.dispose(removed); + } } } diff --git a/crates/yakui-vulkan/src/vulkan_texture.rs b/crates/yakui-vulkan/src/vulkan_texture.rs index a6e2aaf2..7c596c96 100644 --- a/crates/yakui-vulkan/src/vulkan_texture.rs +++ b/crates/yakui-vulkan/src/vulkan_texture.rs @@ -208,6 +208,12 @@ impl UploadQueue { finished.cleanup(vulkan_context.device); } + /// Schedule `texture` to be disposed of after the previous phase completes + pub unsafe fn dispose(&mut self, texture: VulkanTexture) { + let phase = self.in_flight.back_mut().unwrap_or(&mut self.phase); + phase.graveyard.push(texture); + } + unsafe fn push( &mut self, vulkan_context: &VulkanContext, @@ -300,6 +306,7 @@ impl UploadQueue { #[derive(Default)] struct UploadPhase { buffers: Vec<(Buffer, usize)>, + graveyard: Vec, } impl UploadPhase { @@ -307,6 +314,9 @@ impl UploadPhase { for (buffer, _) in &self.buffers { buffer.cleanup(device); } + for texture in &self.graveyard { + texture.cleanup(device); + } } unsafe fn push(&mut self, vulkan_context: &VulkanContext, data: &[u8]) -> (vk::Buffer, usize) {