From 1960655915f06de8d60fc313c04157da32189f31 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 30 Nov 2019 17:35:58 -0800 Subject: [PATCH] window: wayland: fix segfault on shutdown --- window/src/os/wayland/connection.rs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) 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 {