emilk/egui · error
failed to get current context to resize surface
Error message
failed to get current context to resize surface
What it means
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.
Source
Thrown at crates/eframe/src/native/glow_integration.rs:1435
.expect("winit window doesn't exist")
}
fn resize(&mut self, viewport_id: ViewportId, physical_size: winit::dpi::PhysicalSize<u32>) {
let width_px = NonZeroU32::new(physical_size.width).unwrap_or(NonZeroU32::MIN);
let height_px = NonZeroU32::new(physical_size.height).unwrap_or(NonZeroU32::MIN);
if let Some(viewport) = self.viewports.get(&viewport_id)
&& let Some(gl_surface) = &viewport.gl_surface
{
change_gl_context(
&mut self.current_gl_context,
&mut self.not_current_gl_context,
gl_surface,
);
gl_surface.resize(
self.current_gl_context
.as_ref()
.expect("failed to get current context to resize surface"),
width_px,
height_px,
);
}
}
fn get_proc_address(&self, addr: &core::ffi::CStr) -> *const core::ffi::c_void {
self.gl_config.display().get_proc_address(addr)
}
pub(crate) fn remove_viewports_not_in(
&mut self,
viewport_output: &OrderedViewportIdMap<ViewportOutput>,
) {
// GC old viewports
self.viewports
.retain(|id, _| viewport_output.contains_key(id));
self.viewport_from_windowView on GitHub (pinned to 441971a776)
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.
Example fix
// before
if let Some(new_size) = resize_request {
integration.resize(viewport_id, new_size);
}
// after
if let Some(new_size) = resize_request {
if integration.current_gl_context.is_some() {
integration.resize(viewport_id, new_size);
}
} Defensive patterns
Strategy: validation
Validate before calling
// Skip resize when the GL context is not current
if runner.current_gl_context.is_some() {
runner.resize(viewport_id, new_physical_size);
} else {
log::debug!("GL context not current; deferring resize");
} Type guard
fn can_resize(runner: &GlowIntegration) -> bool { runner.current_gl_context.is_some() } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Harness::ui_id is only available for harnesses built with a
- viewport doesn't exist
- winit window doesn't exist
- Tried to update user texture.
- We should always find the root
AI-assisted analysis of emilk/egui@441971a776 (2026-09-12).
Data as JSON: /api/errors/1fbb57a01ccf759a.
Report an issue: GitHub.