Skip to content

panic after dropping window on X11 #414

Closed

Description

@wez

Possibly related to #79, but I'm raising this separately because there is no way for an application to trap this fault.

The issue is that the internal maps are no longer consistent / are invalidated after the drop and the event processing uses unwrap when accessing them.

Example program:

extern crate winit;

fn main() {
    let mut events_loop = winit::EventsLoop::new();

    let _window1 = Some(winit::Window::new(&events_loop).unwrap());
    let mut window2 = Some(winit::Window::new(&events_loop).unwrap());
    let _window3 = Some(winit::Window::new(&events_loop).unwrap());

    let mut num_windows = 3;

    drop(window2.take());

    events_loop.run_forever(|event| {
        match event {
            winit::Event::WindowEvent { event: winit::WindowEvent::Closed, .. } => {
                num_windows -= 1;
                if num_windows == 0 {
                    return winit::ControlFlow::Break;
                }
            },
            _ => (),
        }
        winit::ControlFlow::Continue
    })
}

Stack trace:

Breakpoint 1, rust_panic () at libstd/panicking.rs:433
433	libstd/panicking.rs: No such file or directory.
(gdb) bt
#0  rust_panic () at libstd/panicking.rs:433
#1  0x00005555556d369f in std::panicking::rust_panic_with_hook () at libstd/panicking.rs:418
#2  0x00005555556d3423 in std::panicking::begin_panic_fmt () at libstd/panicking.rs:349
#3  0x00005555556d3353 in rust_begin_unwind () at libstd/panicking.rs:325
#4  0x0000555555712be1 in core::panicking::panic_fmt () at libcore/panicking.rs:72
#5  0x0000555555712b07 in core::panicking::panic () at libcore/panicking.rs:51
#6  0x00005555555784aa in <core::option::Option<T>>::unwrap (self=...) at /checkout/src/libcore/macros.rs:20
#7  0x000055555557a2cb in winit::platform::platform::x11::EventsLoop::process_event (self=0x7fffffffda40, xev=0x7fffffffd8b8, callback=0x7fffffffd980)
    at /home/wez/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.11.1/src/platform/linux/x11/mod.rs:360
#8  0x0000555555578e57 in winit::platform::platform::x11::EventsLoop::run_forever (self=0x7fffffffda40, callback=...)
    at /home/wez/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.11.1/src/platform/linux/x11/mod.rs:188
#9  0x000055555556c428 in winit::platform::platform::EventsLoop::run_forever (self=0x7fffffffda38, callback=...)
    at /home/wez/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.11.1/src/platform/linux/mod.rs:399
#10 0x000055555556fb68 in winit::EventsLoop::run_forever (self=0x7fffffffda38, callback=...)
    at /home/wez/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.11.1/src/lib.rs:231
#11 0x0000555555575881 in winitbug::main () at src/main.rs:14

Activity

  1. added a commit that references this issue on Mar 4, 2018
  2. added
    DS - x11
    on Mar 4, 2018
  3. self-assigned this
    on Mar 4, 2018
  4. francesca64 commented on Mar 4, 2018

    @francesca64
    Member

    I've created a branch that should solve both this and #79.

    The way I implemented Drop for Window is sort of surprising, since all it does is send a WM_DELETE_WINDOW ClientMessage, which the event loop then handles to do the actual cleanup and destroying. I'm not sure how kosher that is on a conceptual level (in terms of what users expect Drop to be responsible for), but it behaves the best of anything I've tried.

    I've also found that the old Drop implementation freezes the event loop, which I've determined to be related to the mutex locking. I still don't understand exactly why that was an issue, but now that the locking is done in the event loop, everything works fine.

  5. francesca64 commented on Mar 23, 2018

    @francesca64
    Member

    Fixed via #416

  6. added a commit that references this issue on Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

DS - x11

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions