{"record":{"id":"ed82790dac6dffb0","repo":"emilk/egui","slug":"failed-to-get-display-handle","errorCode":null,"errorMessage":"Failed to get display handle","messagePattern":"Failed to get display handle","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eframe/src/native/glow_integration.rs","lineNumber":1340,"sourceCode":"                Some(window.scale_factor() as f32),\n                event_loop.system_theme(),\n                self.max_texture_side,\n            )\n        });\n\n        if viewport.gl_surface.is_none() {\n            log::debug!(\"Creating a gl_surface for viewport {viewport_id:?}\");\n\n            // surface attributes\n            let (width_px, height_px): (u32, u32) = window.inner_size().into();\n            let width_px = NonZeroU32::new(width_px).unwrap_or(NonZeroU32::MIN);\n            let height_px = NonZeroU32::new(height_px).unwrap_or(NonZeroU32::MIN);\n            let surface_attributes = {\n                glutin::surface::SurfaceAttributesBuilder::<glutin::surface::WindowSurface>::new()\n                    .build(\n                        window\n                            .window_handle()\n                            .expect(\"Failed to get display handle\")\n                            .as_raw(),\n                        width_px,\n                        height_px,\n                    )\n            };\n\n            log::trace!(\"creating surface with attributes: {surface_attributes:?}\");\n            let gl_surface = unsafe {\n                self.gl_config\n                    .display()\n                    .create_window_surface(&self.gl_config, &surface_attributes)?\n            };\n\n            log::trace!(\"surface created successfully: {gl_surface:?}. making context current\");\n\n            let not_current_gl_context =\n                if let Some(not_current_context) = self.not_current_gl_context.take() {\n                    not_current_context","sourceCodeStart":1322,"sourceCodeEnd":1358,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/eframe/src/native/glow_integration.rs#L1322-L1358","documentation":"While building glutin `SurfaceAttributes`, eframe calls `window.window_handle()` (raw-window-handle's `HasWindowHandle`) and unwraps it with `.expect(\"Failed to get display handle\")`. Note the message is misleading: it fetches the window handle (not the display handle), and panics if the platform backend cannot produce one for the newly created window.","triggerScenarios":"Surface creation for a viewport whose window cannot yield a raw window handle — window already destroyed, unsupported backend, or platform handle conversion failure on X11/Wayland/Win32.","commonSituations":"Wayland/X11 sessions in containers or nested compositors; drivers/backends reporting windows without exportable handles; eframe/egui-winit/raw-window-handle version mismatches; closing a viewport while its surface is being created.","solutions":["Ensure a functional display server is available (valid DISPLAY or WAYLAND_DISPLAY); in CI use Xvfb or run software rendering (LIBGL_ALWAYS_SOFTWARE=1).","Align versions of eframe, egui-winit, glutin, and raw-window-handle (same trait major versions).","Avoid closing/destroying viewports concurrently with surface creation; keep viewport teardown on the same event-loop thread.","If maintaining a fork, use `window_handle().ok()` and return a graceful `Result` error instead of `.expect`."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// preflight display-server check before starting the eframe app\nfn can_create_surfaces() -> bool {\n    cfg!(target_os = \"windows\")\n        || cfg!(target_os = \"macos\")\n        || std::env::var_os(\"WAYLAND_DISPLAY\").is_some()\n        || std::env::var_os(\"DISPLAY\").is_some()\n}","typeGuard":null,"tryCatchPattern":"// internal .expect panic: cannot catch; validate environment first and fail fast\nif !can_create_surfaces() {\n    eprintln!(\"No display server; cannot create GL surfaces\");\n    std::process::exit(1);\n}","preventionTips":["Verify DISPLAY/WAYLAND_DISPLAY or a native window system before launch.","Use software rendering (LIBGL_ALWAYS_SOFTWARE=1) in containers/CI.","Avoid tearing down viewports while their surfaces are being created; serialize on the event loop thread.","Match raw-window-handle major versions across eframe/winit/glutin in Cargo.toml."],"tags":["eframe","glutin","raw-window-handle","surface","panic"],"backgroundTag":"missing-dependency","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}