iced-rs/iced · error

Get window that was just inserted

Error message

Get window that was just inserted

What it means

This panic is an internal invariant check in `WindowMap::insert` (winit/src/window.rs:97): after `self.entries.insert(id, ...)` succeeds, `self.entries.get_mut(&id)` must find the entry. `get_mut` returning None is impossible under normal operation, so `.expect("Get window that was just inserted")` signals a broken invariant rather than a caller-recoverable condition.

Source

Thrown at winit/src/window.rs:97

            id,
            Window {
                raw: window,
                waker,
                state,
                exit_on_close_request,
                surface,
                surface_version,
                renderer,
                mouse_interaction: mouse::Interaction::None,
                redraw_at: None,
                preedit: None,
                ime_state: None,
            },
        );

        self.entries
            .get_mut(&id)
            .expect("Get window that was just inserted")
    }

    pub fn is_empty(&self) -> bool {
        self.entries.is_empty()
    }

    pub fn is_idle(&self) -> bool {
        self.entries
            .values()
            .all(|window| window.redraw_at.is_none())
    }

    pub fn redraw_at(&self) -> Option<Instant> {
        self.entries
            .values()
            .filter_map(|window| window.redraw_at)
            .min()
    }

View on GitHub (pinned to d146509d89)

Solutions

  1. Verify no custom map/hash implementation is substituted for `entries` that could fail to retain the inserted key
  2. Ensure `WindowId` hashing/equality is deterministic and consistent (no random or stateful hashing that changes between insert and lookup)
  3. Avoid concurrent access to the window map; keep all mutation on the event loop thread
  4. If patching the library, replace the expect with `unwrap_or_else(|| panic!("window map lost entry {:?}", id))` for diagnostics

Example fix

null
Defensive patterns

Strategy: validation

Validate before calling

// Rust: validate the map retains entries (only relevant when customizing)
debug_assert!(self.entries.contains_key(&id), "entries must retain inserted id {:?}", id);

Type guard

fn entry_exists(entries: &HashMap<WindowId, WindowState>, id: &WindowId) -> bool {
    entries.contains_key(id)
}

Try / catch

std::panic::catch_unwind(|| window_map.insert(id, state))
    .unwrap_or_else(|_| panic!("window map invariant broken for id {:?}", id));

Prevention

When it happens

Trigger: Only possible if `insert` silently fails or a custom `entries` map implementation misbehaves — e.g. a map type whose `insert` doesn't retain the key, a hasher or map wrapper that evicts the entry, or concurrent mutation if `entries` were wrapped in a re-entrant structure.

Common situations: Practically never hit by library users; encountered when customizing/patching winit's window map (custom hasher, interior mutability, arena wrapper) or when a memory bug corrupts the entries map.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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