{"record":{"id":"1fbb57a01ccf759a","repo":"emilk/egui","slug":"failed-to-get-current-context-to-resize-surface","errorCode":null,"errorMessage":"failed to get current context to resize surface","messagePattern":"failed to get current context to resize surface","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eframe/src/native/glow_integration.rs","lineNumber":1435,"sourceCode":"            .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\"),\n                width_px,\n                height_px,\n            );\n        }\n    }\n\n    fn get_proc_address(&self, addr: &core::ffi::CStr) -> *const core::ffi::c_void {\n        self.gl_config.display().get_proc_address(addr)\n    }\n\n    pub(crate) fn remove_viewports_not_in(\n        &mut self,\n        viewport_output: &OrderedViewportIdMap<ViewportOutput>,\n    ) {\n        // GC old viewports\n        self.viewports\n            .retain(|id, _| viewport_output.contains_key(id));\n        self.viewport_from_window","sourceCodeStart":1417,"sourceCodeEnd":1453,"githubUrl":"https://github.com/emilk/egui/blob/441971a776322a482e371775219380eca812cfa9/crates/eframe/src/native/glow_integration.rs#L1417-L1453","documentation":"In `GlowIntegration::resize`, the code resizes the GL surface using `self.current_gl_context`, panicking with `expect` if that `Option` is `None`. `resize` requires a currently-usable OpenGL context; a `None` means the context is not current (it may live in `not_current_gl_context` after a suspend/make-not-current transition), so the surface cannot be resized now.","triggerScenarios":"A resize event (`ViewportCommand` handling or winit `Resized`) arrives while the glow GL context is in the not-current state — e.g. after `set_swap_interval`/suspend paths moved the context to `not_current_gl_context` and it was not made current again before the resize.","commonSituations":"Window minimize/restore or DPI-change storms on Windows/X11 where eframe temporarily drops the current context; calling resize during initialization or teardown; driver/driver-update environments where `make_current` failed earlier and left the context not current.","solutions":["Upgrade eframe/egui-glcontext — many context-suspend races around resize were fixed in later releases.","Ensure resize only happens while the context is current: re-check the order of make-current vs. resize calls in your fork/integration code.","Avoid triggering resize during teardown (guard against `Resized` events after you stop rendering).","If it happens on minimize, filter/ignore zero-sized or stale resize events as a workaround."],"exampleFix":"// before\nif let Some(new_size) = resize_request {\n    integration.resize(viewport_id, new_size);\n}\n// after\nif let Some(new_size) = resize_request {\n    if integration.current_gl_context.is_some() {\n        integration.resize(viewport_id, new_size);\n    }\n}","handlingStrategy":"validation","validationCode":"// Skip resize when the GL context is not current\nif runner.current_gl_context.is_some() {\n    runner.resize(viewport_id, new_physical_size);\n} else {\n    log::debug!(\"GL context not current; deferring resize\");\n}","typeGuard":"fn can_resize(runner: &GlowIntegration) -> bool { runner.current_gl_context.is_some() }","tryCatchPattern":null,"preventionTips":["Keep eframe/egui updated; many context-suspend races are fixed upstream","Don't process Resized events during teardown or after stopping the frame loop","Ignore zero-size resizes triggered by minimize"],"tags":["panic","opengl","resize","egui","gl-context"],"backgroundTag":"invalid-state-transition","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"}