From 883bd7ea6960b3c44ad1a4f5a8d0ae786c1cec5f Mon Sep 17 00:00:00 2001 From: Chance Date: Tue, 25 Mar 2025 00:32:49 -0400 Subject: [PATCH] exit event loop properly --- engine/Cargo.toml | 8 ++++---- engine/src/core/render/mod.rs | 32 +++++++++++++++++++------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/engine/Cargo.toml b/engine/Cargo.toml index 641f4bb..78db639 100644 --- a/engine/Cargo.toml +++ b/engine/Cargo.toml @@ -12,14 +12,14 @@ crashreport = "1.0.1" dirs-next = "2.0.0" lazy_static.workspace = true -once_cell = "1.20.2" +once_cell = "1.21.1" parking_lot.workspace = true regex = "1.11.1" rustyline = { version = "15.0.0", features = ["derive", "rustyline-derive"] } thiserror = "2.0.11" -tokio = { version = "1.42.0", features = ["macros", "parking_lot","rt-multi-thread"] } -wgpu = "24.0.1" -winit = "0.30.8" +tokio = { version = "1.44.1", features = ["macros", "parking_lot","rt-multi-thread"] } +wgpu = "24.0.3" +winit = "0.30.9" bytemuck = "1.21.0" futures = "0.3.31" cgmath = "0.18.0" diff --git a/engine/src/core/render/mod.rs b/engine/src/core/render/mod.rs index aeeb262..964e332 100644 --- a/engine/src/core/render/mod.rs +++ b/engine/src/core/render/mod.rs @@ -1,6 +1,4 @@ use std::collections::HashMap; -use std::io::{Read, Write}; -use std::ops::Deref; use std::sync::Arc; use ctx::WgpuCtx; @@ -43,15 +41,16 @@ impl ApplicationHandler for App<'_> { match event { WindowEvent::CloseRequested => { if let Some(window) = self.windows.remove(&window_id) { - let mut window = Arc::into_inner(window); - + let mut window = Arc::into_inner(window); + window = None; + // _ = window; drop(window); - + event_loop.exit(); println!("Window: {:?} closed, exiting", window_id); } - if self.windows.is_empty() { - event_loop.exit(); - } + // if self.windows.is_empty() { + // event_loop.exit(); + // } } WindowEvent::KeyboardInput { device_id, @@ -76,7 +75,7 @@ impl ApplicationHandler for App<'_> { winit::keyboard::KeyCode::Escape => { debug!("Escape key pressed, spawning new window"); let win_attr = - Window::default_attributes().with_title("Zenyx - New Window"); + Window::default_attributes().with_title(format!("Zenyx - New Window {}",self.windows.len())); let new_window = Arc::new( event_loop .create_window(win_attr) @@ -93,12 +92,19 @@ impl ApplicationHandler for App<'_> { _ => {} }, WindowEvent::RedrawRequested => { - for window in self.windows.values() { - if let Some(ctx) = &mut self.ctx { - ctx.draw(); + if let Some(ctx) = &mut self.ctx { + ctx.draw(); + } + match self.windows.get(&window_id) { + Some(window) => { + if let Some(ctx) = &mut self.ctx { + ctx.draw(); + } + window.request_redraw(); } - window.request_redraw(); + None => () } + } WindowEvent::Resized(size) => { if let Some(window) = self.windows.get(&window_id) {