{"record":{"id":"4cac85083bfa627a","repo":"emilk/egui","slug":"viewport-doesn-t-exist","errorCode":null,"errorMessage":"viewport doesn't exist","messagePattern":"viewport doesn't exist","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eframe/src/native/glow_integration.rs","lineNumber":1266,"sourceCode":"            if let Err(err) = self.initialize_window(viewport_id, event_loop) {\n                log::error!(\"Failed to initialize a window for viewport {viewport_id:?}: {err}\");\n            }\n        }\n    }\n\n    /// Create a surface, window, and winit integration for the viewport, if missing.\n    #[expect(unsafe_code)]\n    pub(crate) fn initialize_window(\n        &mut self,\n        viewport_id: ViewportId,\n        event_loop: &ActiveEventLoop,\n    ) -> Result {\n        profiling::function_scope!();\n\n        let viewport = self\n            .viewports\n            .get_mut(&viewport_id)\n            .expect(\"viewport doesn't exist\");\n\n        let window = if let Some(window) = &mut viewport.window {\n            window\n        } else {\n            log::debug!(\"Creating a window for viewport {viewport_id:?}\");\n            let window_attributes = egui_winit::apply_monitor_to_window_attributes(\n                egui_winit::create_winit_window_attributes(\n                    &self.egui_ctx,\n                    viewport.builder.clone(),\n                ),\n                &viewport.builder,\n                event_loop,\n            );\n            if window_attributes.transparent()\n                && self.gl_config.supports_transparency() == Some(false)\n                && !cfg!(target_os = \"windows\")\n            {\n                log::error!(\"Cannot create transparent window: the GL config does not support it\");","sourceCodeStart":1248,"sourceCodeEnd":1284,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/eframe/src/native/glow_integration.rs#L1248-L1284","documentation":"`GlowIntegration::initialize_window` looks up the viewport by `viewport_id` in `self.viewports` and `.expect`s it to exist. If a caller (e.g. `initialize_all_windows`) requests initialization of a viewport id that was never registered — or that was removed — the library panics with 'viewport doesn't exist'. This is an internal invariant: all viewports to initialize must already be tracked.","triggerScenarios":"Calling `initialize_window(viewport_id)` for an id not present in `self.viewports`; viewport state cleared/rebuilt between listing and initialization; custom code or patches injecting viewport ids that don't match registered ones.","commonSituations":"Multi-viewport apps where a viewport was closed (viewport info removed from egui) while pending initialization; stale viewport ids cached across frames; races between egui's viewport list and eframe's map.","solutions":["Update eframe/egui to matching versions — stale viewport ids across mismatched egui/eframe versions commonly trigger this.","If you maintain a fork, replace the `.expect` with a `let Some(viewport) = self.viewports.get_mut(&viewport_id) else { return Ok(()) }` skip-and-log.","Make sure viewports closed during a frame are removed from any pending-initialization list before `initialize_all_windows` runs.","Avoid caching `ViewportId`s across frames; derive the set to initialize from the current `self.viewports` snapshot."],"exampleFix":"// before (fork/internal)\nlet viewport = self.viewports.get_mut(&viewport_id).expect(\"viewport doesn't exist\");\n// after\nlet Some(viewport) = self.viewports.get_mut(&viewport_id) else {\n    log::debug!(\"viewport {viewport_id:?} no longer exists; skipping initialization\");\n    return Ok(());\n};","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// defensive pattern for code iterating viewports before eframe initializes them\nfn is_known_viewport(viewports: &std::collections::HashMap<egui::ViewportId, Viewport>, id: &egui::ViewportId) -> bool {\n    viewports.contains_key(id)\n}","tryCatchPattern":"// this is an internal panic, not a Result; guard at the fork/integration layer:\n// replace `.expect(\"viewport doesn't exist\")` with get_mut + early return, and log the stale id.","preventionTips":["Keep eframe and egui on identical versions.","Don't cache ViewportIds across frames; recompute from current state each frame.","Remove closed viewports from any pending list before window initialization runs.","Perform all viewport create/close operations on the single winit event-loop thread."],"tags":["eframe","egui","viewport","panic","lifecycle"],"backgroundTag":"resource-not-found","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"}