rust-windowing / winit

Window handling library in pure Rust
https://docs.rs/winit/
Apache License 2.0
4.88k stars 911 forks source link

Tracing Error When Window Closed #3915

Closed Shadowcat650 closed 2 months ago

Shadowcat650 commented 2 months ago

Description

When the I exit the event loop, a tracing error is given.

Code that caused the error:

use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::{ActiveEventLoop, EventLoop};
use winit::window::{Window, WindowAttributes, WindowId};

fn main() {
    tracing_subscriber::fmt::init();

    let mut app = App {
        window: None
    };

    let event_loop = EventLoop::new().unwrap();
    event_loop.run_app(&mut app).unwrap();
}

struct App {
    window: Option<Window>
}

impl ApplicationHandler for App {
    fn resumed(&mut self, event_loop: &ActiveEventLoop) {
        self.window = Some(event_loop.create_window(WindowAttributes::default()).unwrap());
    }

    fn window_event(&mut self, event_loop: &ActiveEventLoop, _window_id: WindowId, event: WindowEvent) {
        match event {
            WindowEvent::CloseRequested => event_loop.exit(),
            _ => ()
        }
    }
}

The error:

2024-09-11T22:44:09.138281Z ERROR winit::platform_impl::macos::event_handler: tried to run event handler, but no handler was set

macOS version

ProductName:        macOS
ProductVersion:     14.6.1
BuildVersion:       23G93

Winit version

0.30.5

madsmtm commented 2 months ago

I suspect this is due to the window being dropped after the application has exited, and I think it will be fixed by https://github.com/rust-windowing/winit/pull/3895.

In the meantime, try doing self.window = None inside CloseRequested?

Shadowcat650 commented 2 months ago

In the meantime, try doing self.window = None inside CloseRequested?

Thanks, that fixes it.