{"record":{"id":"85e00163f179c64f","repo":"zed-industries/zed","slug":"the-pointer-should-always-be-valid-when-dispatchin","errorCode":null,"errorMessage":"The pointer should always be valid when dispatching in wayland","messagePattern":"The pointer should always be valid when dispatching in wayland","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/gpui_linux/src/linux/wayland/client.rs","lineNumber":439,"sourceCode":"    Path(PathBuf),\n    /// A window from ourselves to raise.\n    Window(ObjectId),\n}\n\nimpl WaylandClientState {\n    fn consume_startup_activation_token(&mut self, surface: &wl_surface::WlSurface) {\n        let Some(startup_activation_token) = self.startup_activation_token.take() else {\n            return;\n        };\n        let Some(activation) = self.globals.activation.as_ref() else {\n            return;\n        };\n        activation.activate(startup_activation_token, surface);\n    }\n}\n\n/// This struct is required to conform to Rust's orphan rules, so we can dispatch on the state but hand the\n/// window to GPUI.\n#[derive(Clone)]\npub struct WaylandClientStatePtr(Weak<RefCell<WaylandClientState>>);\n\nimpl WaylandClientStatePtr {\n    pub fn get_client(&self) -> Rc<RefCell<WaylandClientState>> {\n        self.0\n            .upgrade()\n            .expect(\"The pointer should always be valid when dispatching in wayland\")\n    }\n\n    pub fn dispatch_scheduled_frames(&self) {\n        let Some(client) = self.0.upgrade() else {\n            return;\n        };\n        // Release the client borrow before ticking: the tick re-enters GPUI, which can\n        // borrow the client again (e.g. IME updates).\n        let windows = client\n            .borrow()","sourceCodeStart":421,"sourceCodeEnd":457,"githubUrl":"https://github.com/zed-industries/zed/blob/9d272b036335401f339d024ea94968fd51016c40/crates/gpui_linux/src/linux/wayland/client.rs#L421-L457","documentation":"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.","triggerScenarios":"Thrown at crates/gpui_linux/src/linux/wayland/client.rs:437 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Ensure the event loop is stopped and dispatchers dropped before WaylandClientState is freed","Hold a strong reference during dispatch or exit gracefully when upgrade fails","Check shutdown ordering between platform teardown and proxy event dispatch"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"9d272b036335401f339d024ea94968fd51016c40","analyzedAt":"2026-08-20T19:29:52.058Z","contentChangedAt":"2026-08-20T19:29:52.058Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}