TwinFan / XPMP2

Multiplayer library for X-Plane 11/12 with instancing, TCAS override, and sound
https://twinfan.github.io/XPMP2/
Other
24 stars 16 forks source link

Linux: X-Plane frozen during FMOD shutdown / after FMOD error "not unit length, or perpendicular" #54

Closed TwinFan closed 1 year ago

TwinFan commented 1 year ago

Describe the bug User report: X-Plane froze, last line in log is

LT/XPMP2 ERROR Sound.cpp:835/SoundUpdatesDone: FMOD Error 36 - 'The vectors passed in are not unit length, or perpendicular.' in FMOD_System_Set3DListenerAttributes

To Reproduce / Source Code Example Unclear. But can probably be forced in debugger by sending wrong coordinates into FMOD_System_Set3DListenerAttributes.

Expected behavior

  1. Error shall not freeze X-Plane, check error handling.
  2. Error shall not happen.

Version

Log.txt Log-Snd_Freeze.txt

Additional context Original user report is a comment to LiveTraffic. More discussion then tracked in a support thread.

TwinFan commented 1 year ago

I could not recreate any problem. The error does not appear to me "just so".

I can certainly enforce it via debugger or by adding code that consciously passes non-unit length vectors to FMOD_System_Set3DListenerAttributes, but all that happens then is as per design:

Can only ask affected user to try a debug version that provokes the error to see if once it happens his system is freezing again.

TwinFan commented 1 year ago

Started a support thread for discussion with affected users. A xPilot user joined in with similar issue with xPilot, which also uses XPMP2, also tracked as xpilot-project/xpilot#137.

Turns out: It is not actually the error 36 itself that causes issues, but calling FMOD_System_Release while handling the original error: Currently XPMP2 treats any error returned by the call to FMOD_System_Set3DListenerAttributes as fatal and shuts down the sound system to avoid further errors. Only the shutdown actually causes the freeze.

The very same freeze happens during a normal exit of the plugin at the same place, ie. during the call to FMOD_System_Release.

Users see a connection to the use of the PipeWire module (in absence of PulseAudio) in certain Linux distros. I still can't reproduce in a standard Ubuntu 22.04 installation and hence not confirm the suspicion.

Fix/Workaround: It's easy not to treat error 36 as a fatal error, so that no sound shutdown happens thereafter. We've tested that in an analysis version of LiveTraffic.

But I'm not convinced to remove the final call to FMOD_System_Release during plugin shutdown, as that would mean not to properly clean up FMOD resources. So for the moment the few affected users might need to live with a freeze during shutdown if using XPMP2 sound.