DSP getParameterData silent crash unity

    result = system.createDSPByType(FMOD.DSP_TYPE.FFT, out spectrum);
    FMOD.DSP_PARAMETER_FFT waveFormBuffer;
    IntPtr waveFormPtr = Marshal.AllocHGlobal(Marshal.SizeOf(waveFormBuffer));
    Marshal.StructureToPtr(waveFormBuffer, waveFormPtr, false);

    uint bytes = 0;
    result = spectrum.getParameterData((int)FMOD.DSP_FFT.SPECTRUMDATA, out waveFormPtr, out bytes);

When you run this in the Editor, or in standalone builds, on an "exit" it does a silent crash of Unity.

There are no initialization errors, and if I remove the DSP effect, there is no silent crash. The specific line that seems to cause the crash is the getParameterData call. If you call that a single time it will cause the crash.

Am I perhaps not initializing this correctly? Maybe the marshal/memory allocation calls are incorrect?

You don’t need to allocate unmanaged memory to pass into FMOD. FMOD is not copying the data out, it is returning a pointer to it’s internal data (obviously unmanaged). Getting the spectrum should look like this.

        IntPtr unmanagedData;
        uint unmanagedDataLen = 0;
        result = spectrum.getParameterData((int)FMOD.DSP_FFT.SPECTRUMDATA, out unmanagedData, out unmanagedDataLen);
        FMOD.DSP_PARAMETER_FFT waveFormBuffer = (FMOD.DSP_PARAMETER_FFT)Marshal.PtrToStructure(unmanagedData, typeof(FMOD.DSP_PARAMETER_FFT));
1 Like

Thanks, excellent answer for an off in the stupid moment =p