emilk/egui · error

Window was collapsed

Error message

Window was collapsed

What it means

In the same `show_new_viewport` helper, after the window is shown its inner content is unwrapped. `Window::show` returns `None` for `.inner` when the window body was collapsed (title bar only, no content drawn), so the helper panics with "Window was collapsed" — even though the helper called `.collapsible(false)` on the window.

Source

Thrown at crates/egui/src/context.rs:4386

            out.expect(
                "egui backend is implemented incorrectly - the user callback was never called",
            )
        })
    }

    fn show_embedded_viewport<T>(
        &self,
        new_viewport_id: ViewportId,
        builder: ViewportBuilder,
        viewport_ui_cb: impl FnOnce(&mut Ui) -> T,
    ) -> T {
        crate::Window::from_viewport(new_viewport_id, builder)
            .collapsible(false)
            .show(self, |ui| viewport_ui_cb(ui))
            .unwrap_or_else(|| panic!("Window did not show"))
            .inner
            .unwrap_or_else(|| panic!("Window was collapsed"))
    }
}

/// ## Interaction
impl Context {
    /// Read which widgets are currently being interacted with.
    pub fn interaction_snapshot<R>(&self, reader: impl FnOnce(&InteractionSnapshot) -> R) -> R {
        self.write(|w| reader(&w.viewport().interact_widgets))
    }

    /// The widget currently being dragged, if any.
    ///
    /// For widgets that sense both clicks and drags, this will
    /// not be set until the mouse cursor has moved a certain distance.
    ///
    /// NOTE: if the widget was released this pass, this will be `None`.
    /// Use [`Self::drag_stopped_id`] instead.
    pub fn dragged_id(&self) -> Option<Id> {

View on GitHub (pinned to 441971a776)

Solutions

  1. Clear or fix the persisted window state: `ctx.memory_mut(|m| ...)` remove the window's collapsed flag, or reset egui memory in development.
  2. Ensure nothing collapses the window programmatically before `show_new_viewport` is called.
  3. Open the window once manually (uncollapse) so persisted state is updated, then rely on the helper.
  4. If collapse is possible, use `Window::show` directly and handle the Option rather than this infallible helper.

Example fix

// before
// stale persisted state has the window collapsed
ctx.show_new_viewport(builder, |ui| { ... }); // panics: Window was collapsed
// after
ctx.memory_mut(|mem| mem.data.remove_temp(win_id, "collapsed")); // or clear window state
ctx.show_new_viewport(builder, |ui| { ... });
Defensive patterns

Strategy: validation

Validate before calling

// clear stale collapse state for the viewport window id before showing
ctx.memory_mut(|mem| mem.collapse(Window::from_viewport(new_viewport_id, builder.clone()).id(), false));

Prevention

When it happens

Trigger: Calling `ctx.show_new_viewport(builder, cb)` when the egui window state still reports the window as collapsed — typically stale/persisted collapse state in egui memory overriding the `.collapsible(false)` setting, so the body isn't rendered and `inner` is None.

Common situations: Restarting an app with egui persistence where the viewport window was collapsed when last saved; programmatically collapsing the window earlier in the same frame; viewport state restored from memory.

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


AI-assisted analysis of emilk/egui@441971a776 (2026-09-12). Data as JSON: /api/errors/b8e053387a63dc8f. Report an issue: GitHub.