{"record":{"id":"31764e7be434b7e6","repo":"emilk/egui","slug":"winit-window-doesn-t-exist","errorCode":null,"errorMessage":"winit window doesn't exist","messagePattern":"winit window doesn't exist","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eframe/src/native/glow_integration.rs","lineNumber":1417,"sourceCode":"        } else {\n            log::debug!(\"context is already not current??? could be duplicate suspend event\");\n        }\n        Ok(())\n    }\n\n    fn viewport(&self, viewport_id: ViewportId) -> &Viewport {\n        self.viewports\n            .get(&viewport_id)\n            .expect(\"viewport doesn't exist\")\n    }\n\n    fn window_opt(&self, viewport_id: ViewportId) -> Option<Arc<Window>> {\n        self.viewport(viewport_id).window.clone()\n    }\n\n    fn window(&self, viewport_id: ViewportId) -> Arc<Window> {\n        self.window_opt(viewport_id)\n            .expect(\"winit window doesn't exist\")\n    }\n\n    fn resize(&mut self, viewport_id: ViewportId, physical_size: winit::dpi::PhysicalSize<u32>) {\n        let width_px = NonZeroU32::new(physical_size.width).unwrap_or(NonZeroU32::MIN);\n        let height_px = NonZeroU32::new(physical_size.height).unwrap_or(NonZeroU32::MIN);\n\n        if let Some(viewport) = self.viewports.get(&viewport_id)\n            && let Some(gl_surface) = &viewport.gl_surface\n        {\n            change_gl_context(\n                &mut self.current_gl_context,\n                &mut self.not_current_gl_context,\n                gl_surface,\n            );\n            gl_surface.resize(\n                self.current_gl_context\n                    .as_ref()\n                    .expect(\"failed to get current context to resize surface\"),","sourceCodeStart":1399,"sourceCodeEnd":1435,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/eframe/src/native/glow_integration.rs#L1399-L1435","documentation":"`GlowIntegration::window` calls `window_opt(viewport_id)` and unwraps the result with `expect(\"winit window doesn't exist\")`. A viewport entry exists in `self.viewports`, but its `window: Option<Arc<Window>>` is `None`. The library assumes any viewport present in the map (other than transient states) has an associated winit window; `None` indicates the window was closed/destroyed without removing the viewport entry, or the viewport is still being initialized.","triggerScenarios":"Calling `window(viewport_id)` for a viewport whose `window` field is `None` — typically during teardown, when the window was destroyed (e.g. `ViewportCommand::Close` processed) but the viewport record lingers, or when the id refers to a viewport mid-creation.","commonSituations":"Handling a winit event (resize, redraw, user-close) for a window that was just destroyed; deferred viewport code running after the parent closed the child window; race between close handling and the event loop delivering one more event for the dead id.","solutions":["Prefer `window_opt` in your own integration code and handle the `None` case instead of the panicking `window` API.","Ensure viewport removal happens in the same frame the window is destroyed so `viewports` never holds entries with `None` windows.","Guard event handling against events for closed viewports (check the id before calling `window`).","If reproducible, file an eframe issue with the event sequence; as a workaround disable viewports in `NativeOptions`."],"exampleFix":"// before\nlet window = integration.window(viewport_id);\n// after\nif let Some(window) = integration.window_opt(viewport_id) {\n    // use window\n} else {\n    log::warn!(\"window for {:?} already closed\", viewport_id);\n}","handlingStrategy":"validation","validationCode":"// Prefer the fallible accessor before touching the window\nif let Some(window) = runner.window_opt(viewport_id) {\n    use_window(&window);\n} else {\n    eprintln!(\"viewport {:?} has no window; skipping\", viewport_id);\n}","typeGuard":"fn live_window(v: &Viewport) -> Option<Arc<Window>> { v.window.clone() }","tryCatchPattern":null,"preventionTips":["Use window_opt instead of window in custom integration code","Destroy the viewport record in the same frame its window is closed","Ignore events arriving for ids you have already closed"],"tags":["panic","viewport","winit","egui","window-lifecycle"],"backgroundTag":"internal-invariant-violation","analyzedSha":"441971a776322a482e371775219380eca812cfa9","analyzedAt":"2026-09-12T04:29:21.500Z","contentChangedAt":"2026-09-12T04:29:21.500Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}