diff --git a/window/src/os/wayland/connection.rs b/window/src/os/wayland/connection.rs index 1b6f466ce..527621647 100644 --- a/window/src/os/wayland/connection.rs +++ b/window/src/os/wayland/connection.rs @@ -22,17 +22,25 @@ use toolkit::reexports::client::{Display, EventQueue}; use toolkit::Environment; pub struct WaylandConnection { - pub(crate) display: RefCell, - event_q: RefCell, - pub(crate) environment: RefCell, should_terminate: RefCell, timers: RefCell, pub(crate) tasks: Tasks, pub(crate) next_window_id: AtomicUsize, pub(crate) windows: RefCell>>>, - pub(crate) seat: WlSeat, - pub(crate) keyboard: KeyboardDispatcher, + + // Take care with the destruction order: the underlying wayland + // libraries are not safe and require destruction in reverse + // creation order. This list of fields must reflect that otherwise + // we'll segfault on shutdown. + // Rust guarantees that struct fields are dropped in the order + // they appear in the struct, so the Display must be at the + // bottom of this list. pub(crate) pointer: PointerDispatcher, + pub(crate) keyboard: KeyboardDispatcher, + pub(crate) seat: WlSeat, + pub(crate) environment: RefCell, + event_q: RefCell, + pub(crate) display: RefCell, } impl Evented for WaylandConnection {