iced-rs/iced · critical · compositor::SurfaceError::OutOfMemory

{error:?}

Error message

{error:?}

What it means

During the winit event loop, presenting the compositor surface failed with `compositor::SurfaceError::OutOfMemory`, which the library treats as unrecoverable and aborts with `panic!("{error:?}")`. All other surface errors (Outdated, Lost, etc.) are handled by reconfiguring and redrawing, but OOM cannot be recovered safely.

Source

Thrown at winit/src/lib.rs:947

                        });

                        window.draw_preedit();

                        let present_span = debug::present(id);
                        match current_compositor.present(
                            &mut window.renderer,
                            &mut window.surface,
                            window.state.viewport(),
                            window.state.background_color(),
                            || window.raw.pre_present_notify(),
                        ) {
                            Ok(()) => {
                                present_span.finish();
                            }
                            Err(error) => match error {
                                compositor::SurfaceError::OutOfMemory => {
                                    // This is an unrecoverable error.
                                    panic!("{error:?}");
                                }
                                compositor::SurfaceError::Outdated
                                | compositor::SurfaceError::Lost => {
                                    present_span.finish();

                                    // Reconfigure surface and try redrawing
                                    let physical_size = window.state.physical_size();

                                    if error == compositor::SurfaceError::Lost {
                                        window.surface = current_compositor.create_surface(
                                            window.raw.clone(),
                                            physical_size.width,
                                            physical_size.height,
                                        );
                                    } else {
                                        current_compositor.configure_surface(
                                            &mut window.surface,
                                            physical_size.width,

View on GitHub (pinned to d146509d89)

Solutions

  1. Update GPU drivers (and wgpu backends/Vulkan ICDs) to current versions.
  2. Reduce memory pressure: lower window resolution/scale factor, close other GPU-heavy applications, shrink buffers.
  3. Handle the error upstream by catching the panic or running the app in a supervised process and retrying after freeing resources.
  4. If reproducible on a specific driver/hardware, file a bug with wgpu/iced including `WGPU_BACKEND` details; try a different backend (`WGPU_BACKEND=gl` or `dx12`).

Example fix

// environment workaround
// before: default backend selection
// after
WGPU_BACKEND=gl cargo run --release
Defensive patterns

Strategy: retry

Validate before calling

// Before heavy rendering, handle surface errors in the present path:
match compositor.present(...) {
    Err(compositor::SurfaceError::OutOfMemory) => { /* free resources, recreate */ }
    _ => {}
}

Type guard

fn is_oom(err: &iced::compositor::SurfaceError) -> bool {
    matches!(err, iced::compositor::SurfaceError::OutOfMemory)
}

Try / catch

// The library panics; supervise the process externally or catch at the boundary
let outcome = std::panic::catch_unwind(AssertUnwindSafe(|| app.run(settings)));
if outcome.is_err() { /* log OOM, free GPU resources, relaunch */ }

Prevention

When it happens

Trigger: `Surface::present` (via the compositor present path) returns `SurfaceError::OutOfMemory`, typically when the GPU/driver cannot allocate the swapchain buffer or memory pressure exhausts the graphics allocator.

Common situations: GPU memory exhaustion from large window sizes/high-DPI multi-monitor setups; buggy or outdated graphics drivers; running out of VRAM with many wgpu surfaces; virtualized GPUs with constrained memory (VMs, remote desktop).

Related errors


AI-assisted analysis of iced-rs/iced@d146509d89 (2026-09-11). Data as JSON: /api/errors/77a54a984b1ae922. Report an issue: GitHub.