{"record":{"id":"71b4e58a15d69076","repo":"iced-rs/iced","slug":"create-window","errorCode":null,"errorMessage":"Create window","messagePattern":"Create window","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"winit/src/lib.rs","lineNumber":343,"sourceCode":"                                    window_attributes.with_canvas(self.canvas.take())\n                                };\n\n                                log::info!(\n                                    \"Window attributes for id `{id:#?}`: {window_attributes:#?}\"\n                                );\n\n                                // On macOS, the `position` in `WindowAttributes` represents the \"inner\"\n                                // position of the window; while on other platforms it's the \"outer\" position.\n                                // We fix the inconsistency on macOS by positioning the window after creation.\n                                #[cfg(target_os = \"macos\")]\n                                let mut window_attributes = window_attributes;\n\n                                #[cfg(target_os = \"macos\")]\n                                let position = window_attributes.position.take();\n\n                                let window = event_loop\n                                    .create_window(window_attributes)\n                                    .expect(\"Create window\");\n\n                                #[cfg(target_os = \"macos\")]\n                                if let Some(position) = position {\n                                    window.set_outer_position(position);\n                                }\n\n                                #[cfg(target_arch = \"wasm32\")]\n                                {\n                                    use winit::platform::web::WindowExtWebSys;\n\n                                    let canvas = window.canvas().expect(\"Get window canvas\");\n\n                                    let _ = canvas.set_attribute(\n                                        \"style\",\n                                        \"display: block; width: 100%; height: 100%\",\n                                    );\n\n                                    let window = web_sys::window().unwrap();","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/iced-rs/iced/blob/2cffa99b395d84fe469b44dccb56bbacd2f1a157/winit/src/lib.rs#L325-L361","documentation":"This panic fires when EventLoop::create_window(window_attributes) returns an OsError inside iced's window-opening control (winit/src/lib.rs:341-343). The platform rejected the window creation: no usable graphics/EGL/GLX connection (missing Mesa/libEGL, broken or absent GPU driver), an invalid combination of window attributes (size/position/monitor), or — on the web target, visible in the surrounding code that does `window_attributes.with_canvas(self.canvas.take())` — no HTML canvas for iced to adopt. Because iced unwraps with .expect(\"Create window\"), the app panics while opening the first window or any later window opened at runtime via iced::window::open.","triggerScenarios":"Launching on a machine without working EGL/GLX (containers or minimal Linux images without Mesa, libEGL missing, NVIDIA driver mismatch); remote sessions (VNC/RDP/ssh -X) without 3D acceleration so GLX/EGL initialization fails; on wasm32, starting iced before the DOM contains a <canvas>, so canvas.take() yields None; opening runtime windows with attributes built around a monitor that has since been unplugged; window attributes the windowing system rejects (e.g. zero size).","commonSituations":"Desktop apps deployed to minimal Linux images or sandboxes without GPU libraries; web builds where the canvas element is missing, created late by JS, or its id doesn't match settings.platform_specific.target; multi-window apps on laptops docking/undocking external monitors; driver updates that leave wgpu/winit unable to create a surface; CI smoke tests of the GUI without a virtual display and software GL.","solutions":["Verify a working GL/EGL stack first: run `glxinfo -B` (or `eglinfo`) and confirm it reports a vendor; install Mesa/libEGL packages (libgl1-mesa-dri, libegl1) and matching GPU drivers.","Where there is no real GPU (VM, container, CI), force software rendering: LIBGL_ALWAYS_SOFTWARE=1 and/or WGPU_BACKEND=gl, or install a software EGL implementation (lavapipe/swiftshader).","On wasm, guarantee the canvas exists before iced boots: put the <canvas> in the static HTML, load the wasm module at the end of <body> or on DOMContentLoaded, and match its id to the window settings' platform_specific.target.","When opening windows at runtime, re-query event_loop.primary_monitor()/available_monitors() at call time (as this code does) instead of caching monitor handles, and clamp requested size/position to the current monitor bounds.","Capture the real cause: iced logs the full window_attributes at info level immediately before the call, so run with RUST_LOG=iced_winit=info (plus RUST_BACKTRACE=1) and read the underlying OsError from the panic output."],"exampleFix":"<!-- before (web): iced boots before any canvas exists -->\n<head><script type=\"module\" src=\"pkg/app.js\"></script></head>\n<body></body>\n\n<!-- after: canvas present in static HTML, id matches target -->\n<body>\n  <canvas id=\"iced-canvas\"></canvas>\n  <script type=\"module\" src=\"pkg/app.js\"></script>\n</body>\n\n// main.rs — point iced at that canvas\nlet settings = iced::window::Settings {\n    platform_specific: PlatformSpecific {\n        target: Some(\"iced-canvas\".into()),\n        ..Default::default()\n    },\n    ..Default::default()\n};\niced::application(\"App\", Update::new, View::new)\n    .window(settings)\n    .run()","handlingStrategy":"validation","validationCode":"// Web: confirm the canvas exists before handing control to iced\nfn canvas_ready(target: &str) -> bool {\n    web_sys::window()\n        .and_then(|w| w.document())\n        .and_then(|d| d.query_selector(&format!(\"#{target}\")))\n        .unwrap_or(Ok(None))\n        .is_ok_and(|el| el.is_some())\n}\n\n// Desktop: verify a GL/EGL path exists before first launch\n//   glxinfo -B   ||   eglinfo\n# and for GPU-less environments, launch with:\n#   LIBGL_ALWAYS_SOFTWARE=1 WGPU_BACKEND=gl ./app","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Smoke-test release binaries in a clean container/VM with software GL forced, so missing-driver environments surface gracefully instead of panicking.","On the web, always ship the <canvas> in static HTML and load the wasm module after the DOM; never rely on JS creating the canvas later.","When opening windows at runtime, re-query monitors at call time and clamp position/size to the monitor's current bounds.","Develop with RUST_LOG=iced_winit=info — it prints the exact WindowAttributes before every create_window call, which is the first thing a bug report will need."],"tags":["rust","iced","winit","window-creation","gpu","egl","webassembly","headless","panic","startup"],"backgroundTag":"window-creation-os-error","analyzedSha":"2cffa99b395d84fe469b44dccb56bbacd2f1a157","analyzedAt":"2026-08-16T19:41:49.083Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}