Skip to content

refactor: Consolidate mouse-pick FP-mode guard into getPickRay() - #228

Merged
fbraz3 merged 1 commit into
fbraz3:mainfrom
costin-alupului:fix/consolidate-pick-fpu-guard
Jul 21, 2026
Merged

refactor: Consolidate mouse-pick FP-mode guard into getPickRay()#228
fbraz3 merged 1 commit into
fbraz3:mainfrom
costin-alupului:fix/consolidate-pick-fpu-guard

Conversation

@costin-alupului

Copy link
Copy Markdown

Summary

Follow-up to #222 addressing @meerzulee's review feedback. Closes #227.

Changes

  1. Consolidate the guard into getPickRay(). bugfix: Re-assert FP mode in mouse pick to fix wrong click location with audio active #222 guarded screenToTerrain() and pickDrawable() separately; getPickRay() is the shared chokepoint (also used by screenToWorldAtZ(), calcCameraAreaOffset(), and paths in W3DMouse.cpp / W3DTerrainVisual.cpp), so one guard there covers all callers. The two redundant calls are removed.
  2. Correct the comments. The prior wording asserted an "audio-thread FP env leak" as fact. That's wrong — FPU state is per-thread (FPCR on arm64), so an audio thread can't corrupt the main thread's FP env. Reworded to describe a defensive re-assert of the engine's expected FP mode. The actual root cause (main-thread audio work altering FP state) is handled by fix(audio): guard FP environment at all audio entry points #226.

Net: -12 / +8 lines, no behavior change beyond broader + correctly-documented coverage.

Testing status (disclosed)

⚠️ Not yet re-tested in-game — submitting now to checkpoint the work. It compiles clean on macOS/ARM (arm64, latest main). I will re-test in a skirmish and comment here to confirm move/build clicks still work. Since the change only relocates an existing, already-verified setFPMode() call to the shared function, behavior should be identical.

AI disclosure

Per CONTRIBUTING: authored with AI assistance (Claude); I reviewed the change and will verify it in-game before considering it done.

Follow-up to fbraz3#222 addressing review feedback from @meerzulee:

- Move the single setFPMode() call into getPickRay(), the shared chokepoint
  used by screenToTerrain(), pickDrawable(), screenToWorldAtZ() and others, so
  all pick paths are covered by one guard. Remove the two now-redundant calls.
- Reword the comments to describe a defensive FP-mode re-assert. The previous
  wording stated an "audio-thread FP env leak" as fact, which is incorrect:
  FPU state is per-thread (FPCR on arm64). The likely cause is main-thread
  audio work altering the FP mode, addressed separately in fbraz3#226.

Closes fbraz3#227

AI-assisted: change authored with Claude. Compiles clean on macOS/ARM;
in-game re-test pending (will confirm on the PR).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@fbraz3

fbraz3 commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Hey @costin-alupului, thanks again for the PR.

Could you please keep the PR as a draft until it’s tested?

I usually test these points on both games:

  • Skirmish game (I have some savegames versus 7 hard army for my tests)
  • Intro videos on the campaign have sound
  • Air unit voice lines are working

@costin-alupului
costin-alupului marked this pull request as draft July 20, 2026 13:39
@costin-alupului

Copy link
Copy Markdown
Author

Tested on macOS/ARM (M4 Max, macOS 26) at native fullscreen, audio on — all three areas check out:

Also confirmed a camera-jump stall (control-group double-tap / Space-to-event) that was affected by the same pick math stays fixed.

Marking ready for review. Thanks for the checklist, @fbraz3!

@costin-alupului
costin-alupului marked this pull request as ready for review July 21, 2026 11:07
@fbraz3
fbraz3 merged commit 9f501f7 into fbraz3:main Jul 21, 2026
8 checks passed
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.

Consolidate mouse-pick FP-mode guard into getPickRay() and correct misleading comments

2 participants