Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window does not close under specific conditions. #3673

Open
Pieresqi opened this issue May 2, 2024 · 0 comments
Open

Window does not close under specific conditions. #3673

Pieresqi opened this issue May 2, 2024 · 0 comments
Labels
B - bug Dang, that shouldn't have happened DS - windows

Comments

@Pieresqi
Copy link

Pieresqi commented May 2, 2024

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 Pieresqi added B - bug Dang, that shouldn't have happened DS - windows labels May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B - bug Dang, that shouldn't have happened DS - windows
Development

No branches or pull requests

1 participant