zed-industries/zed · error

The pointer should always be valid when dispatching in wayla

Error message

The pointer should always be valid when dispatching in wayland

What it means

WaylandClientStatePtr::get_client upgrades the Weak reference to the shared Wayland client state and panics if it is gone; dispatch callbacks can outlive client teardown, so firing means a Wayland event was dispatched after the client state was dropped — a teardown-ordering bug.

Source

Thrown at crates/gpui_linux/src/linux/wayland/client.rs:439

    Path(PathBuf),
    /// A window from ourselves to raise.
    Window(ObjectId),
}

impl WaylandClientState {
    fn consume_startup_activation_token(&mut self, surface: &wl_surface::WlSurface) {
        let Some(startup_activation_token) = self.startup_activation_token.take() else {
            return;
        };
        let Some(activation) = self.globals.activation.as_ref() else {
            return;
        };
        activation.activate(startup_activation_token, surface);
    }
}

/// This struct is required to conform to Rust's orphan rules, so we can dispatch on the state but hand the
/// window to GPUI.
#[derive(Clone)]
pub struct WaylandClientStatePtr(Weak<RefCell<WaylandClientState>>);

impl WaylandClientStatePtr {
    pub fn get_client(&self) -> Rc<RefCell<WaylandClientState>> {
        self.0
            .upgrade()
            .expect("The pointer should always be valid when dispatching in wayland")
    }

    pub fn dispatch_scheduled_frames(&self) {
        let Some(client) = self.0.upgrade() else {
            return;
        };
        // Release the client borrow before ticking: the tick re-enters GPUI, which can
        // borrow the client again (e.g. IME updates).
        let windows = client
            .borrow()

View on GitHub (pinned to 9d272b0363)

Solutions

  1. Ensure the event loop is stopped and dispatchers dropped before WaylandClientState is freed
  2. Hold a strong reference during dispatch or exit gracefully when upgrade fails
  3. Check shutdown ordering between platform teardown and proxy event dispatch
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at crates/gpui_linux/src/linux/wayland/client.rs:437 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of zed-industries/zed@9d272b0363 (2026-08-20). Data as JSON: /api/errors/85e00163f179c64f. Report an issue: GitHub.