diff --git a/engine/src/core/render/mod.rs b/engine/src/core/render/mod.rs
index 0eb47b8..b8cf30c 100644
--- a/engine/src/core/render/mod.rs
+++ b/engine/src/core/render/mod.rs
@@ -13,6 +13,12 @@ pub mod ctx;
 struct WindowContext<'window> {
     window: Arc<Window>,
     ctx: WgpuCtx<'window>,
+    main_window: bool
+}
+impl WindowContext<'_> {
+    pub fn is_main_window(&self) -> bool {
+        self.main_window
+    }
 }
 
 #[derive(Default)]
@@ -36,6 +42,7 @@ impl ApplicationHandler for App<'_> {
                 WindowContext {
                     window,
                     ctx: wgpu_ctx,
+                    main_window: true,
                 },
             );
         }
@@ -50,12 +57,10 @@ impl ApplicationHandler for App<'_> {
         match event {
             WindowEvent::CloseRequested => {
                 if let Some(window_context) = self.windows.remove(&window_id) {
+
                     drop(window_context);
                     debug!("Window: {:?} closed, exiting", window_id);
                 }
-                if self.windows.is_empty() {
-                    event_loop.exit();
-                }
             }
             WindowEvent::KeyboardInput {
                 device_id,
@@ -97,6 +102,7 @@ impl ApplicationHandler for App<'_> {
                                 WindowContext {
                                     window: new_window,
                                     ctx: wgpu_ctx,
+                                    main_window: false,
                                 },
                             );
                         }
@@ -119,6 +125,12 @@ impl ApplicationHandler for App<'_> {
                     debug!("Window resized to {:?}", size_str);
                 }
             }
+            WindowEvent::Destroyed => {
+                if  !self.windows.iter().any(|(_,ctx)| ctx.is_main_window()) || self.windows.is_empty() {
+                    self.windows.clear();
+                    event_loop.exit();
+                }
+            }
             _ => trace!("Unhandled window event"),
         }
     }