Fix crash when highlighting a tool over a panel that doesn't own it - #155
Conversation
drawChoice() asserted that, in TOOL_SELECTION mode, the active tool's building name is always present in the panel's types vector. That invariant is false: selectionMode and displayMode are independent axes. Selecting a tool couples it to a panel at pick time, but the player can then tab-cycle the display panel (CONSTRUCTION_VIEW <-> FLAG_VIEW) while the tool stays selected. Repainting the flag panel with a building tool active (or vice versa) left sel unset (-1), and the assert aborted debug builds. Draw the selection highlight only when the active tool actually belongs to the panel being painted. When it doesn't, there is simply nothing to highlight -- a legitimate UI state, not an error. Ported from PR #129 (feat/ai-trainer-support), original commit 9bffb5f by kylelutze.
genixpro
left a comment
There was a problem hiding this comment.
The sel >= 0 guard correctly permits a selected tool to be absent from the displayed panel. A focused harness running the complete production drawChoice method with a recording graphics stub reproduced the base assertion failure and passed on this head for mismatched and matching tools in both panel layouts, on macOS arm64 and Linux x86_64.
Validation: a clean integration checkout combining #153–#158 built successfully with scons release=1 on macOS arm64 and Ubuntu 26.04 x86_64; both binaries passed --version startup checks, and the existing CppUnit suite passed all 12 tests on Linux. This PR also has passing Ubuntu 22.04/24.04 and Windows CI. Validation was source review and automated checks; no interactive gameplay test.
Bugfix ported from PR #129 (feat/ai-trainer-support), split out to shrink #129's diff against master per Leo's request.
drawChoice() asserted that, in TOOL_SELECTION mode, the active tool's building name is always present in the panel's types vector. That invariant is false: selectionMode and the displayed panel are independent axes. Selecting a tool couples it to a panel at pick time, but the player can then tab-cycle the display panel while the tool stays selected, leaving sel unset (-1). Draw the highlight only when the tool actually belongs to the panel being painted.
Original commit: 9bffb5f by kylelutze