ValveSoftware / steam-audio

Steam Audio
https://valvesoftware.github.io/steam-audio/
Apache License 2.0
2.2k stars 152 forks source link

ArrayMath crashes on x86_64 macOS and Linux during HRTF creation #359

Closed Ravbug closed 2 weeks ago

Ravbug commented 2 weeks ago

System Information Please provide the following information about your system:

Issue Description SteamAudio on x86_64 macOS and Linux compiled to not use Intel IPP crashes during HRTF creation. This issue does not affect arm64 macOS or x86_64 Windows. Configure output:

-- CMAKE_CXX_FLAGS: 
-- Could NOT find IPP (missing: IPP_core_LIBRARY IPP_vm_LIBRARY IPP_s_LIBRARY IPP_INCLUDE_DIR) 
-- Disabling IPP
-- Found PFFFT: PFFFT  
-- Found MySOFA: mysofa-static  
-- Found FlatBuffers: $<TARGET_FILE:flatc> (found version "23.5.26") 
-- Could NOT find ISPC (missing: ISPC_EXECUTABLE) (Required is exact version "1.12")
-- Could NOT find Embree (missing: Embree_sse2_LIBRARY Embree_sse4_LIBRARY Embree_avx_LIBRARY Embree_avx2_LIBRARY Embree_lexers_LIBRARY Embree_math_LIBRARY Embree_simd_LIBRARY Embree_sys_LIBRARY Embree_tasking_LIBRARY Embree_INCLUDE_DIR) (Required is exact version "2.17")
-- Disabling Embree

Steps To Reproduce Steps to reproduce the behavior:

  1. Compile SteamAudio for x86_64 macOS or Linux without Intel IPP.
  2. Compile and run the included reproducible case
  3. See error

If you are able to provide a minimal project or minimal source code that reproduces the issue, include a link to the project/code here.

int main(){
    IPLContext steamAudioContext;
    IPLContextSettings contextSettings{
        .version = STEAMAUDIO_VERSION,
    };
    auto errorCode = iplContextCreate(&contextSettings, &steamAudioContext);

    IPLAudioSettings audioSettings{};
    audioSettings.samplingRate = 44100;
    audioSettings.frameSize = 512;

    IPLHRTFSettings hrtfSettings{
        .type = IPL_HRTFTYPE_DEFAULT,
        .volume = 1.0
    };

    IPLHRTF steamAudioHRTF = nullptr;
    errorCode = iplHRTFCreate(steamAudioContext, &audioSettings, &hrtfSettings, &steamAudioHRTF);  // crashes here

    return 0;
}

Stack Trace:

Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)

#0  0x0000000104c94ab4 in ipl::float4::load(float const*) at steam-audio/core/src/core/sse_float4.h:171
#1  0x0000000104db3629 in ipl::ArrayMath::addConstant(int, float const*, float, float*) at steam-audio/core/src/core/array_math.cpp:273
#2  0x0000000104ca93ae in ipl::HRTFDatabase::decomposeToMagnitudePhase(ipl::Array<float, 3ul> const&, ipl::Array<float, 3ul>&, ipl::Array<float, 3ul>&) at steam-audio/core/src/core/hrtf_database.cpp:333
#3  0x0000000104ca833e in ipl::HRTFDatabase::HRTFDatabase(ipl::HRTFSettings const&, int, int) at steam-audio/core/src/core/hrtf_database.cpp:57
#4  0x0000000104ca9e89 in ipl::HRTFDatabase::HRTFDatabase(ipl::HRTFSettings const&, int, int) at steam-audio/core/src/core/hrtf_database.cpp:52
#5  0x0000000104d6a8a2 in std::__1::__shared_ptr_emplace<ipl::HRTFDatabase, ipl::allocator<ipl::HRTFDatabase>>::__shared_ptr_emplace[abi:ue170006]<ipl::HRTFSettings&, int&, int&>(ipl::allocator<ipl::HRTFDatabase>, ipl::HRTFSettings&, int&, int&) at /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__memory/shared_ptr.h:303
#6  0x0000000104d6a64d in std::__1::__shared_ptr_emplace<ipl::HRTFDatabase, ipl::allocator<ipl::HRTFDatabase>>::__shared_ptr_emplace[abi:ue170006]<ipl::HRTFSettings&, int&, int&>(ipl::allocator<ipl::HRTFDatabase>, ipl::HRTFSettings&, int&, int&) at /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__memory/shared_ptr.h:292
#7  0x0000000104d6a549 in std::__1::shared_ptr<ipl::HRTFDatabase> std::__1::allocate_shared[abi:ue170006]<ipl::HRTFDatabase, ipl::allocator<ipl::HRTFDatabase>, ipl::HRTFSettings&, int&, int&, void>(ipl::allocator<ipl::HRTFDatabase> const&, ipl::HRTFSettings&, int&, int&) at /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/usr/include/c++/v1/__memory/shared_ptr.h:1023
#8  0x0000000104d69fe5 in std::__1::shared_ptr<ipl::HRTFDatabase> ipl::make_shared<ipl::HRTFDatabase, ipl::HRTFSettings&, int&, int&>(ipl::HRTFSettings&, int&, int&) at steam-audio/core/src/core/memory_allocator.h:203
#9  0x0000000104d69ebf in api::CHRTF::CHRTF(api::CContext*, _IPLAudioSettings_t*, IPLHRTFSettings*) at steam-audio/core/src/core/api_hrtf.cpp:58
#10 0x0000000104d6a08d in api::CHRTF::CHRTF(api::CContext*, _IPLAudioSettings_t*, IPLHRTFSettings*) at steam-audio/core/src/core/api_hrtf.cpp:37
#11 0x0000000104d6a2db in api::CContext::createHRTF(_IPLAudioSettings_t*, IPLHRTFSettings*, api::IHRTF**) at steam-audio/core/src/core/api_hrtf.cpp:100
#12 0x0000000104d604c8 in ::iplHRTFCreate(IPLContext, IPLAudioSettings *, IPLHRTFSettings *, IPLHRTF *) at steam-audio/core/src/core/phonon_interfaces.h:1105
image

I changed some of the SSE intrinsics to their non-aligned versions which enabled the macOS build to get further, so it appears to be an alignment issue.

wolframw commented 2 weeks ago

Looks like a duplicate of #351, which was fixed by 60a8220763519e434072fb45d621c7fcdc67dcdb.

lakulish commented 2 weeks ago

Duplicate of #351