winit icon indicating copy to clipboard operation
winit copied to clipboard

Window does not close under specific conditions.

Open Pieresqi opened this issue 1 year ago • 6 comments

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

Pieresqi avatar May 02 '24 08:05 Pieresqi

I can't reproduce this issue on Windows 11

notgull avatar Jun 24 '24 04:06 notgull

me too

Microsoft Windows [Version 10.0.19045.4651]

tasogare3710 avatar Aug 05 '24 13:08 tasogare3710

If you do self.window = None inside the CloseRequsted handling does it work correctly?

kchibisov avatar Aug 05 '24 13:08 kchibisov

Sorry, forget it. I could not reproduce it with that Minimal repro code. But I've seen that bug.

tasogare3710 avatar Aug 05 '24 16:08 tasogare3710

Noticed this issue also.

If you do self.window = None inside the CloseRequsted handling does it work correctly?

This helped.

Windows 11.

hakolao avatar Aug 25 '24 19:08 hakolao