{"record":{"id":"fad274097c08f7e5","repo":"linebender/druid","slug":"unable-to-acquire-underlying-compositor-to-create-fad274","errorCode":null,"errorMessage":"unable to acquire underlying compositor to create an xdg surface","messagePattern":"unable to acquire underlying compositor to create an xdg surface","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"druid-shell/src/backend/wayland/surfaces/mod.rs","lineNumber":165,"sourceCode":"    }\n\n    fn shared_mem(&self) -> wlc::Main<WlShm> {\n        match self.inner.upgrade() {\n            None => panic!(\"unable to acquire underlying compositor to acquire shared memory\"),\n            Some(c) => c.shared_mem(),\n        }\n    }\n\n    fn get_xdg_positioner(&self) -> wlc::Main<xdg_positioner::XdgPositioner> {\n        match self.inner.upgrade() {\n            None => panic!(\"unable to acquire underlying compositor to create an xdg positioner\"),\n            Some(c) => c.get_xdg_positioner(),\n        }\n    }\n\n    fn get_xdg_surface(&self, s: &wlc::Main<WlSurface>) -> wlc::Main<xdg_surface::XdgSurface> {\n        match self.inner.upgrade() {\n            None => panic!(\"unable to acquire underlying compositor to create an xdg surface\"),\n            Some(c) => c.get_xdg_surface(s),\n        }\n    }\n\n    fn zwlr_layershell_v1(&self) -> Option<wlc::Main<ZwlrLayerShellV1>> {\n        match self.inner.upgrade() {\n            None => {\n                tracing::warn!(\n                    \"unable to acquire underyling compositor to acquire the layershell manager\"\n                );\n                None\n            }\n            Some(c) => c.zwlr_layershell_v1(),\n        }\n    }\n}\n","sourceCodeStart":147,"sourceCodeEnd":182,"githubUrl":"https://github.com/linebender/druid/blob/0f8b1195e4e073f9597f2865299c3d18f8e4005f/druid-shell/src/backend/wayland/surfaces/mod.rs#L147-L182","documentation":"Same weak-reference pattern as the positioner variant: get_xdg_surface upgrades a weak compositor reference to fetch the xdg_surface object for a WlSurface. If the strong compositor handle was already dropped, upgrade fails and the library panics. It means a Wayland xdg surface (the protocol object backing a toplevel) cannot be created because the compositor is unreachable.","triggerScenarios":"Creating a new window/surface (via Surface::new or layer-shell paths) when the compositor handle backing the weak reference has been dropped, so the upgrade inside get_xdg_surface returns None.","commonSituations":"Window creation during or after Wayland compositor teardown; storing a Surface without keeping the CompositorHandle/WindowHandle alive; delayed window creation (e.g. spawning a window on a background task) after the initiating handle was dropped.","solutions":["Keep the CompositorHandle alive until every surface creation completes; store it in your application state alongside the surfaces.","Create windows before any teardown of the compositor; avoid creating windows from tasks that can outlive the main handle.","Verify you are not using a Surface whose originating compositor has disconnected (e.g. after compositor crash/restart).","Restructure so surface creation happens synchronously in the same scope where the compositor handle exists."],"exampleFix":"// before: surface outlives the compositor handle\nlet surface;\n{\n    let compositor = connect()?;\n    surface = Surface::new(&compositor, handler, size);\n} // handle dropped, later new/replace panics\n\n// after: own the handle with the surface\nstruct Window {\n    _compositor: CompositorHandle,\n    surface: Surface,\n}","handlingStrategy":"try-catch","validationCode":"// Check compositor reachability before creating windows\nif !compositor.can_upgrade() {\n    eprintln!(\"compositor handle dead; cannot create window\");\n    return;\n}","typeGuard":"fn can_create_surface(inner: &Weak<CompositorInner>) -> bool {\n    inner.upgrade().is_some()\n}","tryCatchPattern":"std::panic::catch_unwind(AssertUnwindSafe(|| Surface::new(&handle, handler, size)))\n    .map_err(|_| WindowError::CompositorGone)","preventionTips":["Create windows in the same scope/lifetime as the compositor handle","Store the CompositorHandle in long-lived application state","Never spawn window-creation tasks that can outlive the main handle","Treat compositor disconnect as fatal for all pending window creations"],"tags":["wayland","panic","lifecycle","compositor"],"backgroundTag":"internal-invariant-violation","analyzedSha":"0f8b1195e4e073f9597f2865299c3d18f8e4005f","analyzedAt":"2026-09-10T14:27:34.582Z","contentChangedAt":"2026-09-10T14:27:34.582Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}