diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 85 |
1 files changed, 40 insertions, 45 deletions
diff --git a/src/main.rs b/src/main.rs index 883b587..f8f44a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1361,55 +1361,15 @@ impl Drop for Surreality { #[allow(unsafe_code)] fn drop(&mut self) { if let Some(permanent) = self.permanent.replace(None) { - let device = permanent.device; - let instance = permanent.instance; - - unsafe { device.device_wait_idle() }.unwrap(); + unsafe { permanent.device.device_wait_idle() }.unwrap(); if let Some(window_dressing) = self.window_dressing.replace(None) { - let concurrency = window_dressing.concurrency; - let swapchain = window_dressing.swapchain; - - for semaphore in concurrency.image_available_semaphores { - unsafe { device.destroy_semaphore(semaphore, None) }; - } - - for semaphore in concurrency.rendering_finished_semaphores { - unsafe { device.destroy_semaphore(semaphore, None) }; - } - - for fence in concurrency.frame_fences { - unsafe { device.destroy_fence(fence, None) }; - } - - unsafe { - device.destroy_command_pool(window_dressing.command_pool, None) - }; - - for framebuffer in window_dressing.framebuffers { - unsafe { device.destroy_framebuffer(framebuffer, None) }; - } - - unsafe { - device.destroy_pipeline(window_dressing.pipeline, None) - }; - - unsafe { - device.destroy_render_pass(window_dressing.render_pass, None) - }; - - unsafe { - device.destroy_pipeline_layout( - window_dressing.pipeline_layout, None) - }; - - for view in swapchain.image_views { - unsafe { device.destroy_image_view(view, None) }; - } - - unsafe { device.destroy_swapchain_khr(swapchain.swapchain, None) }; + window_dressing.destroy(&permanent); } + let device = permanent.device; + let instance = permanent.instance; + unsafe { device.destroy_device(None) }; unsafe { instance.destroy_surface_khr(permanent.surface, None) }; @@ -1430,6 +1390,41 @@ impl Drop for Surreality { } } +impl WindowDressing { + #[allow(unsafe_code)] + fn destroy(self, permanent: &PermanentGraphicsState) { + let device = &permanent.device; + + for semaphore in self.concurrency.image_available_semaphores { + unsafe { device.destroy_semaphore(semaphore, None) }; + } + + for semaphore in self.concurrency.rendering_finished_semaphores { + unsafe { device.destroy_semaphore(semaphore, None) }; + } + + for fence in self.concurrency.frame_fences { + unsafe { device.destroy_fence(fence, None) }; + } + + unsafe { device.destroy_command_pool(self.command_pool, None) }; + + for framebuffer in self.framebuffers { + unsafe { device.destroy_framebuffer(framebuffer, None) }; + } + + unsafe { device.destroy_pipeline(self.pipeline, None) }; + unsafe { device.destroy_render_pass(self.render_pass, None) }; + unsafe { device.destroy_pipeline_layout(self.pipeline_layout, None) }; + + for view in self.swapchain.image_views { + unsafe { device.destroy_image_view(view, None) }; + } + + unsafe { device.destroy_swapchain_khr(self.swapchain.swapchain, None) }; + } +} + impl ApplicationHandler for Surreality { fn resumed(&mut self, event_loop: &ActiveEventLoop) { ignore_errors(move || { |