{"record":{"id":"37db3e28ac73fbab","repo":"iced-rs/iced","slug":"get-window-that-was-just-inserted","errorCode":null,"errorMessage":"Get window that was just inserted","messagePattern":"Get window that was just inserted","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"winit/src/window.rs","lineNumber":97,"sourceCode":"            id,\n            Window {\n                raw: window,\n                waker,\n                state,\n                exit_on_close_request,\n                surface,\n                surface_version,\n                renderer,\n                mouse_interaction: mouse::Interaction::None,\n                redraw_at: None,\n                preedit: None,\n                ime_state: None,\n            },\n        );\n\n        self.entries\n            .get_mut(&id)\n            .expect(\"Get window that was just inserted\")\n    }\n\n    pub fn is_empty(&self) -> bool {\n        self.entries.is_empty()\n    }\n\n    pub fn is_idle(&self) -> bool {\n        self.entries\n            .values()\n            .all(|window| window.redraw_at.is_none())\n    }\n\n    pub fn redraw_at(&self) -> Option<Instant> {\n        self.entries\n            .values()\n            .filter_map(|window| window.redraw_at)\n            .min()\n    }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/iced-rs/iced/blob/d146509d893945de5c304cfaf4301335eee278bd/winit/src/window.rs#L79-L115","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify no custom map/hash implementation is substituted for `entries` that could fail to retain the inserted key","Ensure `WindowId` hashing/equality is deterministic and consistent (no random or stateful hashing that changes between insert and lookup)","Avoid concurrent access to the window map; keep all mutation on the event loop thread","If patching the library, replace the expect with `unwrap_or_else(|| panic!(\"window map lost entry {:?}\", id))` for diagnostics"],"exampleFix":"null","handlingStrategy":"validation","validationCode":"// Rust: validate the map retains entries (only relevant when customizing)\ndebug_assert!(self.entries.contains_key(&id), \"entries must retain inserted id {:?}\", id);","typeGuard":"fn entry_exists(entries: &HashMap<WindowId, WindowState>, id: &WindowId) -> bool {\n    entries.contains_key(id)\n}","tryCatchPattern":"std::panic::catch_unwind(|| window_map.insert(id, state))\n    .unwrap_or_else(|_| panic!(\"window map invariant broken for id {:?}\", id));","preventionTips":["Do not replace or wrap the internal entries map with custom behavior","Use deterministic, consistent hashing for WindowId","Keep all window-map mutations on a single thread","When forking/patching, add debug_asserts around insert/get_mut pairs"],"tags":["rust","internal-invariant","panic","window-management","winit"],"backgroundTag":"internal-invariant-violation","analyzedSha":"d146509d893945de5c304cfaf4301335eee278bd","analyzedAt":"2026-09-11T16:54:14.229Z","contentChangedAt":"2026-09-11T16:54:14.229Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}