{"record":{"id":"c44009771938f226","repo":"slint-ui/slint","slug":"c-nativewindowhandle-created-with-null-xcb-wind","errorCode":null,"errorMessage":"C++: NativeWindowHandle created with null xcb window handle","messagePattern":"C\\+\\+: NativeWindowHandle created with null xcb window handle","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"api/cpp/platform.rs","lineNumber":814,"sourceCode":"            RawDisplayHandle::Windows(raw_window_handle::WindowsDisplayHandle::new()),\n        ));\n        Box::into_raw(Box::new(handle)) as CppRawHandleOpaque\n    }\n\n    #[unsafe(no_mangle)]\n    pub unsafe extern \"C\" fn slint_new_raw_window_handle_x11_xcb(\n        window: u32,\n        visual_id: u32,\n        connection: *mut c_void,\n        screen: core::ffi::c_int,\n    ) -> CppRawHandleOpaque {\n        use raw_window_handle::{XcbDisplayHandle, XcbWindowHandle};\n        let handle = CppRawHandle::from((\n            RawWindowHandle::Xcb({\n                let mut hnd = XcbWindowHandle::new(\n                    window\n                        .try_into()\n                        .expect(\"C++: NativeWindowHandle created with null xcb window handle\"),\n                );\n                hnd.visual_id = visual_id.try_into().ok();\n                hnd\n            }),\n            RawDisplayHandle::Xcb(XcbDisplayHandle::new(\n                core::ptr::NonNull::new(connection),\n                screen,\n            )),\n        ));\n        Box::into_raw(Box::new(handle)) as CppRawHandleOpaque\n    }\n\n    #[unsafe(no_mangle)]\n    pub unsafe extern \"C\" fn slint_new_raw_window_handle_x11_xlib(\n        window: core::ffi::c_ulong,\n        visual_id: core::ffi::c_ulong,\n        display: *mut c_void,\n        screen: core::ffi::c_int,","sourceCodeStart":796,"sourceCodeEnd":832,"githubUrl":"https://github.com/slint-ui/slint/blob/bb937076de3f7919766c1f25e2e969367cf77e9a/api/cpp/platform.rs#L796-L832","documentation":"When wrapping an XCB window for the C++ API, the u32 window id is converted into raw-window-handle's XcbWindowHandle whose NonNull window field rejects 0 via try_into().expect(...). A zero window id is not a valid X window, so the library panics with this message. It enforces the invariant that a handle references a real X server window.","triggerScenarios":"Passing window=0 (uninitialized or disconnected xcb_connection state) to slint_new_raw_window_handle_xcb from C++, e.g. before xcb_create_window completed or after the window was destroyed.","commonSituations":"X11 apps that call the Slint interop before their xcb window exists, stale window ids after window teardown, or errors from xcb_create_window ignored so the id remains 0.","solutions":["Verify the window id is non-zero before constructing the handle.","Check xcb_create_window's xcb_generic_error_t result to ensure the window was actually created.","Reorder code so the X window is created and flushed before Slint's NativeWindowHandle is built.","Re-query the valid window id from your windowing layer instead of reusing a stale one."],"exampleFix":"// before (C++)\nuint32_t window = 0;\nauto handle = slint::NativeWindowHandle::from_xcb(connection, window, visual_id);\n// after\nif (window == 0) throw std::runtime_error(\"no xcb window created yet\");\nauto handle = slint::NativeWindowHandle::from_xcb(connection, window, visual_id);","handlingStrategy":"validation","validationCode":"// C++ caller, before constructing the handle\nif (window == 0) {\n    throw std::invalid_argument(\"cannot create NativeWindowHandle: null xcb window id\");\n}\n// also check xcb errors after window creation\nif (xcb_connection_has_error(connection)) { /* reconnect */ }","typeGuard":"// C++ helper\nbool is_valid_xcb_window(xcb_connection_t *c, uint32_t w) {\n    return w != 0 && xcb_connection_has_error(c) == 0;\n}","tryCatchPattern":null,"preventionTips":["Only construct the Slint handle after xcb_create_window succeeds (check the returned cookie/error).","Verify xcb_connection_has_error() is 0 before use.","Never reuse window ids after window destruction.","Order initialization: connect -> create window -> flush -> wrap handle.","Log xcb errors instead of ignoring cookies."],"tags":["cpp","x11","xcb","window-handle","panic"],"backgroundTag":"null-argument","analyzedSha":"bb937076de3f7919766c1f25e2e969367cf77e9a","analyzedAt":"2026-09-16T01:37:20.251Z","contentChangedAt":"2026-09-16T01:37:20.251Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}