vk: fix double free of image views in intermediates

This commit is contained in:
chyyran 2023-01-13 14:54:08 -05:00
parent e9a1518c5d
commit f85e44a3b9
3 changed files with 12 additions and 7 deletions

View file

@ -145,7 +145,7 @@ pub(crate) struct FilterCommon {
/// These Vulkan objects must stay alive until the command buffer is submitted /// These Vulkan objects must stay alive until the command buffer is submitted
/// to the rendering queue, and the GPU is done with the objects. /// to the rendering queue, and the GPU is done with the objects.
#[must_use] #[must_use]
pub struct FrameIntermediates { struct FrameIntermediates {
device: ash::Device, device: ash::Device,
image_views: Vec<vk::ImageView>, image_views: Vec<vk::ImageView>,
owned: Vec<OwnedImage>, owned: Vec<OwnedImage>,
@ -170,10 +170,10 @@ impl FrameIntermediates {
/// Dispose of the intermediate objects created during a frame. /// Dispose of the intermediate objects created during a frame.
pub fn dispose(&mut self) { pub fn dispose(&mut self) {
for image_view in &self.image_views { for image_view in self.image_views.drain(0..) {
if *image_view != vk::ImageView::null() { if image_view != vk::ImageView::null() {
unsafe { unsafe {
self.device.destroy_image_view(*image_view, None); self.device.destroy_image_view(image_view, None);
} }
} }
} }
@ -181,6 +181,12 @@ impl FrameIntermediates {
} }
} }
impl Drop for FrameIntermediates {
fn drop(&mut self) {
self.dispose()
}
}
impl FilterChain { impl FilterChain {
/// Load the shader preset at the given path into a filter chain. /// Load the shader preset at the given path into a filter chain.
pub fn load_from_path( pub fn load_from_path(
@ -579,7 +585,7 @@ impl FilterChain {
cmd: vk::CommandBuffer, cmd: vk::CommandBuffer,
options: Option<FrameOptions>, options: Option<FrameOptions>,
) -> error::Result<()> { ) -> error::Result<()> {
let mut intermediates = &mut self.intermediates[count % self.intermediates.len()]; let intermediates = &mut self.intermediates[count % self.intermediates.len()];
intermediates.dispose(); intermediates.dispose();
// limit number of passes to those enabled. // limit number of passes to those enabled.

View file

@ -338,7 +338,7 @@ impl VulkanWindow {
.queue_present(vulkan.base.graphics_queue, &present_info) .queue_present(vulkan.base.graphics_queue, &present_info)
.unwrap(); .unwrap();
vulkan.base.device.device_wait_idle().unwrap(); // vulkan.base.device.device_wait_idle().unwrap();
// intermediates.dispose(); // intermediates.dispose();
} }
} }

View file

@ -19,7 +19,6 @@ mod util;
mod vulkan_primitives; mod vulkan_primitives;
mod vulkan_state; mod vulkan_state;
pub use filter_chain::FrameIntermediates;
pub use filter_chain::FilterChain; pub use filter_chain::FilterChain;
pub use filter_chain::VulkanDevice; pub use filter_chain::VulkanDevice;
pub use filter_chain::VulkanInstance; pub use filter_chain::VulkanInstance;