exit event loop properly

This commit is contained in:
Chance 2025-03-25 00:32:49 -04:00 committed by BitSyndicate
parent 06de4a85e5
commit 883bd7ea69
2 changed files with 23 additions and 17 deletions

View file

@ -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"

View file

@ -1,6 +1,4 @@
use std::collections::HashMap;
use std::io::{Read, Write};
use std::ops::Deref;
use std::sync::Arc;
use ctx::WgpuCtx;
@ -44,14 +42,15 @@ impl ApplicationHandler for App<'_> {
WindowEvent::CloseRequested => {
if let Some(window) = self.windows.remove(&window_id) {
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();
}
match self.windows.get(&window_id) {
Some(window) => {
if let Some(ctx) = &mut self.ctx {
ctx.draw();
}
window.request_redraw();
}
None => ()
}
}
WindowEvent::Resized(size) => {
if let Some(window) = self.windows.get(&window_id) {