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

winit 0.30 panics on exit on macOS #3668

Closed
matanui159 opened this issue May 1, 2024 · 1 comment · Fixed by #3684
Closed

winit 0.30 panics on exit on macOS #3668

matanui159 opened this issue May 1, 2024 · 1 comment · Fixed by #3684
Labels
B - bug Dang, that shouldn't have happened DS - macos

Comments

@matanui159
Copy link
Contributor

Description

Using this very simple setup that just creates a single window and exits on close:

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

struct App {
    window: Option<Window>,
}

impl App {
    fn new() -> Self {
        Self {
            window: None
        }
    }
}

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

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

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

At exit it will panic with the following error:

thread 'main' panicked at [...]/winit-0.30.0/src/platform_impl/macos/app_delegate.rs:147:39:
a delegate was not configured on the application
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

While this isn't the biggest issue since it was already exiting, it prevents doing any checks/cleanup after the event loop has run. Using similar code for 0.29 doesn't cause any issues, and neither does using run_app_on_demand.

macOS version

ProductName:            macOS
ProductVersion:         14.4.1
BuildVersion:           23E224

Winit version

0.30.0

@madsmtm
Copy link
Member

madsmtm commented May 5, 2024

Thanks for the reproducer. Enabling a full backtrace reveals the issue to happen when dropping the Window, inside windowWillClose:.

This will be fixed by #3684, in the meantime, you can prevent this issue by dropping the window yourself inside exiting or the CloseRequested event:

WindowEvent::CloseRequested => {
    let _ = self.window.take();
    event_loop.exit();
}

kchibisov pushed a commit that referenced this issue May 6, 2024
The delegate is only weakly referenced by NSApplication, so getting it
from there may fail if the event loop has been dropped.

Fixes #3668.
kchibisov pushed a commit that referenced this issue May 6, 2024
The delegate is only weakly referenced by NSApplication, so getting it
from there may fail if the event loop has been dropped.

Fixes #3668.
notgull pushed a commit that referenced this issue Jun 1, 2024
The delegate is only weakly referenced by NSApplication, so getting it
from there may fail if the event loop has been dropped.

Fixes #3668.
kchibisov pushed a commit that referenced this issue Jun 10, 2024
The delegate is only weakly referenced by NSApplication, so getting it
from there may fail if the event loop has been dropped.

Fixes #3668.
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 - macos
Development

Successfully merging a pull request may close this issue.

2 participants