Window does not close under specific conditions.
Description
Hi,
Window does not close if I click on Close button (on either window decorations or taskbar) and event_loop.exit() is called from about_to_wait. It just sort of stays there and does nothing. But it will close if I move mouse over window surface.
I am not sure if this is only Windows "problem" or it happens on other platforms too.
Minimal repro code:
fn main() -> Result<(), Box<dyn std::error::Error>> {
winit::event_loop::EventLoop::new()?.run_app(&mut App {
should_exit: false,
window: None,
})?;
Ok(())
}
struct App {
should_exit: bool,
window: Option<winit::window::Window>,
}
impl winit::application::ApplicationHandler for App {
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
self.window.get_or_insert_with(|| {
event_loop
.create_window(winit::window::WindowAttributes::default())
.unwrap()
});
}
fn window_event(
&mut self,
_: &winit::event_loop::ActiveEventLoop,
_: winit::window::WindowId,
event: winit::event::WindowEvent,
) {
match event {
winit::event::WindowEvent::CloseRequested => self.should_exit = true,
_ => (),
}
}
fn about_to_wait(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
if self.should_exit {
event_loop.exit()
}
}
}
Should be event_loop.exit() moved into window_event instead of self.should_exit = true then it will work as expected.
i got this "should exit bool pattern" from example control_flow so maybe that example has this issue too.
Thanks!
Windows version
Microsoft Windows [Version 10.0.22631.3447]
Winit version
0.30.0
I can't reproduce this issue on Windows 11
me too
Microsoft Windows [Version 10.0.19045.4651]
If you do self.window = None inside the CloseRequsted handling does it work correctly?
Sorry, forget it. I could not reproduce it with that Minimal repro code. But I've seen that bug.
Noticed this issue also.
If you do
self.window = Noneinside theCloseRequstedhandling does it work correctly?
This helped.
Windows 11.