summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-07-09 13:26:32 -0700
committerIrene Knapp <ireneista@irenes.space>2026-07-09 13:26:32 -0700
commit4b5ceb8d7fef310349de138b9b811e6abfa9efe3 (patch)
tree443813b26a8ce079505844db696a3246853fb012
parent7873d17c1bc87974a436f8eafb714e5e0779c329 (diff)
move the details of dropping WindowDressing into a new function
this will help with the re-creation thing

Force-Push: yes
Change-Id: I74d70c7dd1d11ade0d1d4cf0a0e20da45b76e942
-rw-r--r--src/main.rs85
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 || {