[Core] Fix unaligned SIMD load crash in ArrayMath and race conditions during shutdown#515
Open
Aper-mesa wants to merge 1 commit intoValveSoftware:masterfrom
Open
[Core] Fix unaligned SIMD load crash in ArrayMath and race conditions during shutdown#515Aper-mesa wants to merge 1 commit intoValveSoftware:masterfrom
Aper-mesa wants to merge 1 commit intoValveSoftware:masterfrom
Conversation
… shutdown 1. src/core/array_math.cpp Fix: In ArrayMath::multiplyAccumulate (complex version), specifically within the else branch handling unaligned memory, changed float4::load to float4::loadu. Reason: The previous code incorrectly used an aligned load instruction (load) inside the fallback branch explicitly meant for unaligned data. This caused crashes (Access Violation) when the accumulation buffer (accum) was not 16-byte aligned. 2. src/core/hrtf_database.cpp Fix: Added validity checks for this pointer and input parameters in HRTFDatabase::ambisonicsHRTF. Reason: During application shutdown (e.g., stopping PIE in Unreal Engine), the main thread may destroy the HRTFDatabase instance while the audio thread is still processing the final frame. This resulted in a "read access violation" where this was nullptr or invalid. The check prevents the crash by returning early. 3. src/core/path_effect.cpp Fix: Added null pointer checks for hrtfForChannel before passing it to ArrayMath::scaleAccumulate inside PathEffect::apply. Reason: As a side effect of the HRTFDatabase fix, if ambisonicsHRTF returns early (due to the shutdown race condition), the hrtfForChannel pointers remain nullptr. Without this check, ArrayMath attempts to read from a null pointer, leading to a secondary crash. Impact Significantly improved stability when using Steam Audio with Wwise/Unreal, particularly when exiting the game or switching levels. Fixed deterministic crashes on hardware/compilers that strictly enforce SIMD alignment requirements.
lakulish
reviewed
Feb 19, 2026
| const complex_t** hrtf) const | ||
| { | ||
| { | ||
| if (!this) |
Collaborator
There was a problem hiding this comment.
I'm curious as to why the check for !this is needed. What scenario leads to this function being called with this being null? I would say the issue lies somewhere in the caller to this function, which probably needs to check whether the HRTFDatabase instance is valid.
| const complex_t* in2, | ||
| complex_t* accum) | ||
| { | ||
| if (!in1 || !in2 || !accum || size <= 0 || reinterpret_cast<uintptr_t>(accum) == 0xFFFFFFFFFFFFFFFF) |
Collaborator
There was a problem hiding this comment.
Why the explicit check for accum being 0xFFFFFFFFFFFFFFFF? Curious as to what scenario leads to this specific value. If it's invalid memory you're testing for, it may have some other value too, which this wouldn't catch.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. src/core/array_math.cpp
Fix: In ArrayMath::multiplyAccumulate (complex version), specifically within the else branch handling unaligned memory, changed float4::load to float4::loadu.
Reason: The previous code incorrectly used an aligned load instruction (load) inside the fallback branch explicitly meant for unaligned data. This caused crashes (Access Violation) when the accumulation buffer (accum) was not 16-byte aligned.
2. src/core/hrtf_database.cpp
Fix: Added validity checks for this pointer and input parameters in HRTFDatabase::ambisonicsHRTF.
Reason: During application shutdown (e.g., stopping PIE in Unreal Engine), the main thread may destroy the HRTFDatabase instance while the audio thread is still processing the final frame. This resulted in a "read access violation" where this was nullptr or invalid. The check prevents the crash by returning early.
3. src/core/path_effect.cpp
Fix: Added null pointer checks for hrtfForChannel before passing it to ArrayMath::scaleAccumulate inside PathEffect::apply.
Reason: As a side effect of the HRTFDatabase fix, if ambisonicsHRTF returns early (due to the shutdown race condition), the hrtfForChannel pointers remain nullptr. Without this check, ArrayMath attempts to read from a null pointer, leading to a secondary crash.
Impact
Significantly improved stability when using Steam Audio with Wwise/Unreal, particularly when exiting the game or switching levels.
Fixed deterministic crashes on hardware/compilers that strictly enforce SIMD alignment requirements.