godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91.61k stars 21.28k forks source link

Unhandled Exception when changing audio devices while device-specific Windows spatial audio filters are active. #10222

Closed bunnitech closed 6 years ago

bunnitech commented 7 years ago

Operating system or device - Godot version: Win10x64pro v1703 b15063.540 w/Asus Sabertooth x79 using Realtek ALC892 audio chipset, Windows spatial sound filters active. Godot v3.0 alpha 1536cc4

Issue description: I executed Godot, then while it was idle on the project selection interface, I plugged in my headphones. On my system (Win10x64pro v1703 b15063.540 w/Asus Sabertooth x79 using Realtek ALC892 audio chipset) my headphone jack in the front disables the rear speaker and makes the headphones (considered another device) the primary Windows audio output device. When this occurred, Godot crashed. This did not happen when I tried to simulate it by changing my audio device in the Windows audio device manager with a new instance of Godot loaded to the same state. The crash also did not occur when I unplugged my headphones, only when plugging them in. This led me to suspect the problem is not with changing devices. I realized I was using the Dolby Atmos audio filter with 7.1 virtual surround enabled (Windows 10 spatial audio), which is configured only for use with my... headphones. When I right-clicked my audio TSA icon and hit the menu option for Atmos, I found it had silently crashed, and Windows had now detected it, offering to reenable the application. I then disabled Atmos, and all filters. I ran Godot and repeatedly plugged/unplugged the jack. Everything was fine. I activated another filter, Windows Sonic for Headphones, again with virtual surround on. Again Godot crashes on device change. Disabling the virtual surround had no effect, still crashes. Also tested with the editor in other states, like with a project loaded, same result as expected. Opening the editor and toggling the effect on my headphone device settings while they are active causes no error.

MSVS2015 JIT debugger reports an unhandled win32 exception at 0x0007FFF6EF9A7CA5

Breaking execution at the exception puts me on the last brace of RtApi :: error. errorText_ reads "RtApiDs::callbackEvent: error (Buffer lost) getting current write position!"

Conclusion Changing audio devices while Windows spatial sound filters are enabled causes an unhandled exception due to the output stream buffer being lost. But why is this a problem only when using spatial audio with device changes, not software changes? Is this actually a Windows bug to work around? I'm not sure how to best handle this, so I leave the code to others this time.

Steps to reproduce: Enable spatial audio filters in Win10CE. With Godot loaded, plug/unplug headphone jack on an audio chipset with jack detection and retasking causing the filter to become enabled/disabled by the device change notification.

bunnitech commented 7 years ago

Hey I found something else out today. When enabling spatial audio, Windows sets the device to 44khz without telling you... I couldn't make Godot throw an exception by changing bit or sample rates, I tried.

vnen commented 7 years ago

Can you test with 2.1.4 beta? There is an old issue like that (#5211) that's supposed to be fixed.

bunnitech commented 7 years ago

I tried with the windows binary you provided a link to, I couldn't make it crash no matter what I did. :) Hmm...

marcelofg55 commented 7 years ago

Did you test this on latest master? This shouldn't be happening anymore with the new WASAPI driver.

akien-mga commented 6 years ago

No answer, so assuming fixed in 3.0 and later. Please comment if you can still reproduce the issue in the latest stable or development versions.