ValveSoftware / steam-audio

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

[C api / Rust bindings] Crash upon calling iplSimulatorRunReflections in minimal setup (status access violation) #335

Open GitGhillie opened 3 months ago

GitGhillie commented 3 months ago

System Information

Issue Description I'm trying to integrate the FMOD plugin into a Rust game engine which has been working great with direct effects, but now I'm trying to add support for reflections/reverb and ran into a crash when calling iplSimulatorRunReflections. So I tried to recreate the issue with just the C api and the rust bindings that I'm using and ran into the same issue.

I expect debugging Rust bindings is out of scope for Valve, but I wonder if in general my approach is correct? The setup can be seen here, including the settings for the simulator, listener and the source: https://gist.github.com/GitGhillie/b8b56c077e73e77ae16a3b81619c8c33

Let me know if I missed any information or if there is anything I can do to help debug this.

Crash Dump I do get some warnings before the crash, but if I understand correctly they are not relevant for the setup I have so far.

2024-03-25T20:41:13.713212Z  WARN steamaudio::context: Warning: createSimulator: invalid IPLint32: settings->numVisSamples = 0
2024-03-25T20:41:13.720854Z  WARN steamaudio::context: Warning: setInputs: invalid IPLfloat32: inputs->reverbScale[iBand] = 0.000000
2024-03-25T20:41:13.721199Z  WARN steamaudio::context: Warning: setInputs: invalid IPLfloat32: inputs->reverbScale[iBand] = 0.000000
2024-03-25T20:41:13.721547Z  WARN steamaudio::context: Warning: setInputs: invalid IPLfloat32: inputs->reverbScale[iBand] = 0.000000
2024-03-25T20:41:13.721902Z  WARN steamaudio::context: Warning: setInputs: invalid IPLfloat32: inputs->hybridReverbTransitionTime = 0.000000
2024-03-25T20:41:13.722209Z  WARN steamaudio::context: Warning: setInputs: invalid IPLfloat32: inputs->hybridReverbOverlapPercent = 0.000000
error: process didn't exit successfully: `target\debug\examples\direct_effect.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
GitGhillie commented 3 months ago

So far it looks like source->reflectionState.accumEnergyField.get() returns a nullptr in this line: https://github.com/ValveSoftware/steam-audio/blob/bbf020ab3690db999ae6f28ddc4422303b5d04e8/core/src/core/simulation_manager.cpp#L227

So when it tries to access that element in energyFields it results in a violation here: https://github.com/ValveSoftware/steam-audio/blob/bbf020ab3690db999ae6f28ddc4422303b5d04e8/core/src/core/reflection_simulator.cpp#L181

Not sure yet why source->reflectionState.accumEnergyField.get() is returning a nullptr.

GitGhillie commented 3 months ago

Looks like it's necessary to pass IPL_SIMULATIONFLAGS_REFLECTIONS when creating the source, even though the Programmer's Guide only suggests setting the inputs with iplSourceSetInputs(source, IPL_SIMULATIONFLAGS_REFLECTIONS, &inputs);. Is this the intended behavior or is it just the docs that need updating?