Skip to content

fix(audio): guard FP environment at all audio entry points#226

Merged
fbraz3 merged 1 commit into
mainfrom
fix/audio-fpu-guard-hardening
Jul 20, 2026
Merged

fix(audio): guard FP environment at all audio entry points#226
fbraz3 merged 1 commit into
mainfrom
fix/audio-fpu-guard-hardening

Conversation

@meerzulee

@meerzulee meerzulee commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Follow-up to #222 for the audio side.

Audio code called from the main thread can leave the FP environment in a bad state on macOS/ARM. We've seen this as wrong mouse picks (#215) and as music affecting physics on non-x86.

init(), update() and addAudioEvent() already had ScopedFPUGuard, but the other entry points didn't. This adds the guard to all of them in MiniAudioManager (which macOS actually uses), OpenALAudioManager (including selectProvider and friend_forcePlayAudioEventRTS), and MiniAudioStream for video audio. readPCM/seekPCM run on the mixer thread, so I left those alone.

Mechanical change, 44 guard insertions and one include.

FPU state is per-thread, so fixing the mixer thread wouldn't help. The problem has to come from audio work running on the main thread, and guarding every entry point closes that window wherever it happens.

I don't have the Vulkan SDK on this machine, so relying on CI for the build. I boot-tested the #222 artifact and confirmed macOS uses the MiniAudio backend.

Two separate follow-ups remain: music decodes whole tracks synchronously on the main thread (causes the gaps at track changes), and there are still unguarded pick paths on the view side, as discussed in #222.

AI disclosure per CONTRIBUTING: written with AI assistance (Claude), reviewed by me.

Audio code invoked from the main thread (miniaudio, OpenAL, video audio
streaming) can leave the FP environment in a state that skews game math
on macOS/ARM - observed as wrong-tile mouse picks (#215) and music
affecting physics calculations on non-x86 platforms.

init(), update() and addAudioEvent() were already guarded; extend
ScopedFPUGuard to the remaining public entry points of MiniAudioManager,
OpenALAudioManager and MiniAudioStream so the engine FP mode is
re-asserted whenever audio work returns to game code mid-frame.
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