Skip to content

Fix crash when highlighting a tool over a panel that doesn't own it - #155

Merged
genixpro merged 1 commit into
masterfrom
junior/fix-drawchoice-panel-crash
Sep 6, 2026
Merged

Fix crash when highlighting a tool over a panel that doesn't own it#155
genixpro merged 1 commit into
masterfrom
junior/fix-drawchoice-panel-crash

Conversation

@Giszmo

@Giszmo Giszmo commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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

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 genixpro left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@genixpro
genixpro merged commit 0f5bab6 into master Sep 6, 2026
3 checks passed
@genixpro
genixpro deleted the junior/fix-drawchoice-panel-crash branch September 6, 2026 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants