{"record":{"id":"35244578db9b7d64","repo":"linebender/druid","slug":"error-allocating-shared-memory","errorCode":null,"errorMessage":"error allocating shared memory","messagePattern":"error allocating shared memory","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"druid-shell/src/backend/wayland/surfaces/buffers.rs","lineNumber":79,"sourceCode":"    pending_buffer_borrowed: Cell<bool>,\n\n    /// Shared memory to allocate buffers in\n    shm: RefCell<Shm>,\n}\n\nimpl<const N: usize> Buffers<N> {\n    /// Create a new `Buffers` object.\n    ///\n    pub fn new(wl_shm: wl::Main<WlShm>, size: RawSize) -> Rc<Self> {\n        assert!(N >= 2, \"must be at least 2 buffers\");\n        Rc::new(Self {\n            released: Cell::new(Vec::new()),\n            buffers: Cell::new(None),\n            pending: Cell::new(0),\n            size: Cell::new(size),\n            recreate_buffers: Cell::new(true),\n            pending_buffer_borrowed: Cell::new(false),\n            shm: RefCell::new(Shm::new(wl_shm).expect(\"error allocating shared memory\")),\n        })\n    }\n\n    /// Get the physical size of the buffer.\n    pub fn size(&self) -> RawSize {\n        self.size.get()\n    }\n\n    /// Request that the size of the buffer is changed.\n    pub fn set_size(&self, updated: RawSize) {\n        assert!(!updated.is_empty(), \"window size must not be empty\");\n        let old = self.size.replace(updated);\n        self.recreate_buffers.set(old != updated);\n    }\n\n    /// Request painting the next frame.\n    ///\n    /// This calls into user code. To avoid re-entrancy, ensure that we are not already in user","sourceCodeStart":61,"sourceCodeEnd":97,"githubUrl":"https://github.com/linebender/druid/blob/0f8b1195e4e073f9597f2865299c3d18f8e4005f/druid-shell/src/backend/wayland/surfaces/buffers.rs#L61-L97","documentation":"Panic raised by an `.expect()` when creating a `Shm` wrapper over the wayland `wl_shm` global fails during `Surface::new`. Wayland shared-memory (shm) allocation is how the shell gets pixel buffers to the compositor; if the protocol object cannot be created or its initial round-trip fails, there is no fallback path, so the library deliberately aborts surface construction.","triggerScenarios":"Calling surface/window creation APIs (e.g. `Surface::new` in the wayland backend) on a compositor that does not expose a working `wl_shm` global, a broken/stale wayland connection, or a compositor that rejects the shm protocol object during initialization.","commonSituations":"Running under a compositor or remote-display setup without wl_shm support (e.g. some nested/special-purpose compositors), connecting over a broken WAYLAND_SOCKET/WAYLAND_DISPLAY environment, sandboxed environments (flatpak/containers) that filter wayland globals, or version mismatches between the client library and compositor.","solutions":["Verify the compositor exposes wl_shm (e.g. `wayland-info`); switch to a standard compositor (Mutter, KWin, wlroots-based) if not","Check WAYLAND_DISPLAY / WAYLAND_SOCKET / XDG_RUNTIME_DIR environment variables point at a live, writable socket","Ensure the app is not running in a sandbox that blocks wayland globals; adjust sandbox permissions or fall back to X11 backend","Update wayland-rs / smithay-client-toolkit dependencies and the compositor to compatible versions"],"exampleFix":"// before (library code, unavoidable)\nlet shm = Shm::new(wl_shm).expect(\"error allocating shared memory\");\n// after (caller-side guard: don't build surfaces on compositors lacking wl_shm)\nlet globals = GlobalsState::new_from_thread(&conn).unwrap();\nassert!(globals.contents().bind_list().iter().any(|g| g.interface == wl_shm::WlShm::name()), \"compositor lacks wl_shm\");","handlingStrategy":"validation","validationCode":"// Before creating wayland surfaces, confirm wl_shm is bound\n// (using wayland-client's globals)\nlet has_shm = globals\n    .contents()\n    .bind_list()\n    .iter()\n    .any(|g| g.interface == wl_shm::WlShm::name());\nif !has_shm {\n    eprintln!(\"compositor does not support wl_shm; cannot render\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":"// Rust panics here, not Results; recover at process level:\nlet result = std::panic::catch_unwind(|| run_app());\nif result.is_err() {\n    eprintln!(\"failed to init wayland shm; falling back to X11 backend\");\n}","preventionTips":["Verify compositor support with `wayland-info` before deploying to a target environment","Pin and test wayland-rs/smithay versions against your CI compositor","Test inside the same sandbox/flatpak permissions used in production","Keep WAYLAND_DISPLAY/XDG_RUNTIME_DIR checks in your startup diagnostics"],"tags":["wayland","shared-memory","gui","panic"],"backgroundTag":"module-init-failed","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"}