Crash in DSP getNumParameters

Hi, we’ve been seeing some crashes and traced it back to the SteamAudio FmodStudioAudioEngineSource which calls getNumParameters/UpdateParameters on a DSP.

Stack Trace

11 ntdll 0x00007ffbf799147e KiUserExceptionDispatcher
12 fmodstudio 0x00007ffac3f06294
13 fmodstudio 0x00007ffac3f0d904
14 GameAssembly 0x00007ffabcc2b861 DSP_setParameterInt_m0EF6219224CC767DF9E1FB53BE5EED654DD8D317 (C:\Users\Documents\1Projects\Project Colombia\Library\Bee\artifacts\WinPlayerBuildProgram\il2cppOutput\cpp\FMODUnity.cpp:26575)
15 GameAssembly 0x00007ffabeafed54 FMODStudioAudioEngineSource_UpdateParameters_m62C27D9CBBEEEAD3DC8A5705F6A7D02D995CCB26 (C:\Users\Documents\1Projects\Project Colombia\Library\Bee\artifacts\WinPlayerBuildProgram\il2cppOutput\cpp\SteamAudioFMODStudio.cpp:973)
16 GameAssembly 0x00007ffabc7413b9 il2cpp::vm::Runtime::InvokeWithThrow (C:\Program Files\Unity\Hub\Editor\2022.3.51f1\Editor\Data\il2cpp\libil2cpp\vm\Runtime.cpp:609)
17 GameAssembly 0x00007ffabc740e69 il2cpp::vm::Runtime::Invoke (C:\Program Files\Unity\Hub\Editor\2022.3.51f1\Editor\Data\il2cpp\libil2cpp\vm\Runtime.cpp:594)
18 UnityPlayer 0x0000000000791514 scripting_gc_wbarrier_set_field (C:\build\output\unity\unity\Runtime\ScriptingBackend\Il2Cpp\ScriptingNativeApi_Il2Cpp.inline.h:120)
19 UnityPlayer 0x0000000000791514 (C:\build\output\unity\unity\Runtime\ScriptingBackend\ScriptingNativeTypes.h:55)
20 UnityPlayer 0x00000000007914fc scripting_method_invoke (C:\build\output\unity\unity\Runtime\ScriptingBackend\Il2Cpp\ScriptingApi_Il2Cpp.cpp:290)
21 UnityPlayer 0x00000000007914ef (C:\build\output\unity\unity\Runtime\Scripting\ScriptingInvocation.cpp:298)
22 UnityPlayer 0x00000000007914b3 (C:\build\output\unity\unity\Runtime\Scripting\ScriptingInvocation.h:71)
23 UnityPlayer 0x00007ffac1f21514 MonoBehaviour::CallMethodIfAvailable (C:\build\output\unity\unity\Runtime\Mono\MonoBehaviour.cpp:488)
24 UnityPlayer 0x0000000000794667 scripting_gc_wbarrier_set_field (C:\build\output\unity\unity\Runtime\ScriptingBackend\Il2Cpp\ScriptingNativeApi_Il2Cpp.inline.h:120)
25 UnityPlayer 0x0000000000794667 (C:\build\output\unity\unity\Runtime\ScriptingBackend\ScriptingNativeTypes.h:33)
26 UnityPlayer 0x0000000000794667 (C:\build\output\unity\unity\Runtime\Scripting\ScriptingObjectOfType.h:25)
27 UnityPlayer 0x0000000000794667 IsInstanceValid (C:\build\output\unity\unity\Runtime\Mono\MonoBehaviour.cpp:294)
28 UnityPlayer 0x00007ffac1f24667 MonoBehaviour::AddToManager (C:\build\output\unity\unity\Runtime\Mono\MonoBehaviour.cpp:1528)
29 UnityPlayer 0x00007ffac1f24041 MonoBehaviour::AwakeFromLoad (C:\build\output\unity\unity\Runtime\Mono\MonoBehaviour.cpp:1391)

We’re on an older fmod version, I’ve been looking through the release notes and saw 1 fix for passing null to setParameterData that might be related. The next thing I’m trying is updating to the newest 2.02 minor for our next patch to see if it helps, but I can’t repro the crash so it’s a bit hard to verify quickly.
I wanted to ask here in case anyone has an idea or pointer. I already asked over on the SteamAudio GitHub a while back but haven’ heard back.

Initially I thought checking for a valid dsp handle and then the parameters could help, but that only changed the crash from setParameter to getNumParameters.

Code

public override void UpdateParameters(SteamAudioSource source)
{
CheckForChangedEventInstance();

        FindDSP(source.gameObject);

        if (!mFoundDSP || !mDSP.hasHandle())
            return;

        var res = mDSP.getNumParameters(out int numParams);
        if (res != FMOD.RESULT.OK)
        {
            #if UNITY_EDITOR || DEVELOPMENT_BUILD
            //Debug.LogWarning($"getNumParameters failed: {res} {mDSP.handle}, has handle {mDSP.hasHandle()} ");
            #endif
            return;
        }

        if (numParams < 0 || kSimulationOutputsParamIndex >= numParams)
        {
            Debug.LogWarning($"invalid params count {numParams}");
            return;
        }

        if(mHandle != -1)
            mDSP.setParameterInt(kSimulationOutputsParamIndex, mHandle);
    }

Steam Audio version: 4.7.0
Unity version: 2022.3.51
FMOD Studio version: 2.02.22

Hi,

Thank you for the info. Are you able to create a stripped out project that is able to reproduce the issue and upload it to your profile for me to test?

If not, are you able to share the FindDSP function?

no, sadly I have not been able to reproduce the crash myself, I only have our cloud exception reporting to go off.

this is the FindDSP code

Code

void FindDSP(GameObject gameObject)
{
if (mFoundDSP)
return;

        mEventEmitter = gameObject.GetComponent<FMODUnity.StudioEventEmitter>();
        if (mEventEmitter == null)
            return;

        mEventInstance = mEventEmitter.EventInstance;
        if (!mEventInstance.isValid())
            return;

        FMOD.ChannelGroup channelGroup;
        mEventInstance.getChannelGroup(out channelGroup);

        int numDSPs;
        channelGroup.getNumDSPs(out numDSPs);

        for (var i = 0; i < numDSPs; ++i)
        {
            channelGroup.getDSP(i, out mDSP);

            var dspName = "";
            var dspVersion = 0u;
            var dspNumChannels = 0;
            var dspConfigWidth = 0;
            var dspConfigHeight = 0;
            mDSP.getInfo(out dspName, out dspVersion, out dspNumChannels, out dspConfigWidth, out dspConfigHeight);

            if (dspName == "Steam Audio Spatializer")
            {
                mFoundDSP = true;
                return;
            }
        }
    }

is there any flag I can check on the DSP before the call to possibly prevent the crash?

here’s the full steamaudio file https://github.com/ValveSoftware/steam-audio/blob/master/unity/src/project/SteamAudioUnity/Assets/Plugins/SteamAudio/Scripts/FMODStudio/FMODStudioAudioEngineSource.cs