drop_overlay_rect panics via HashMap index operator on unknown PileType #26

Closed
opened 2026-05-19 18:44:35 +00:00 by funman300 · 0 comments
Owner

File

solitaire_engine/src/cursor_plugin.rs line 388

Description

layout.pile_positions[pile] uses the Index trait on HashMap<PileType, Vec2>, which panics if the key is absent. This violates CLAUDE.md §2.3 (no unwrap() / panic!() in runtime game logic). While compute_layout is expected to populate all pile positions, this is an implicit runtime invariant — any future pile variant added without updating compute_layout would produce an unrecoverable panic during a drag operation.

Fix

Replace with layout.pile_positions.get(pile).copied().unwrap_or_default() or log a warning and return a fallback rect.

## File `solitaire_engine/src/cursor_plugin.rs` line 388 ## Description `layout.pile_positions[pile]` uses the `Index` trait on `HashMap<PileType, Vec2>`, which panics if the key is absent. This violates CLAUDE.md §2.3 (no `unwrap()` / `panic!()` in runtime game logic). While `compute_layout` is expected to populate all pile positions, this is an implicit runtime invariant — any future pile variant added without updating `compute_layout` would produce an unrecoverable panic during a drag operation. ## Fix Replace with `layout.pile_positions.get(pile).copied().unwrap_or_default()` or log a warning and return a fallback rect.
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: funman300/Ferrous-Solitaire#26