Switching Audio Input Source Crashes Snes9x (Windows 10)

If you're having problems with Snes9x, or think you've found a bug, this is the place to be.
Post Reply
WKRPinNJ
Snes9x White Belt
Posts: 3
Joined: Thu Mar 26, 2020 11:00 am

Switching Audio Input Source Crashes Snes9x (Windows 10)

Post by WKRPinNJ »

Hi,

As someone who uses bluetooth headphones a lot and jumps back & forth from desktop to mobile all the time, I've been having this issue where the software freezes whenever returning to the desktop. It also happens whenever the audio source is changed from headset to speakers and vice versa.

Is this a known issue? What is the best solution? I'm currently using v1.60, but the problem has been happening for a long time and the last few versions did it as well.

Thanks.
mcc
Snes9x White Belt
Posts: 5
Joined: Thu Jan 17, 2008 4:19 am

Re: Switching Audio Input Source Crashes Snes9x (Windows 10)

Post by mcc »

I am seeing this same problem on Windows 10. It freezes 100% of the time if I plug in or unplug headphones. My laptop is running the "realtek hd audio manager" (it came with this and i'm not sure I can turn it off).
mcc
Snes9x White Belt
Posts: 5
Joined: Thu Jan 17, 2008 4:19 am

Re: Switching Audio Input Source Crashes Snes9x (Windows 10)

Post by mcc »

Update: I have now tested with 1.6 and 1.54 from the snes9x-rr fork, the freeze happens hard in 1.6, in 1.54 it merely slows down by like 50x but doesn't stop responding to input events…
mcc
Snes9x White Belt
Posts: 5
Joined: Thu Jan 17, 2008 4:19 am

Re: Switching Audio Input Source Crashes Snes9x (Windows 10)

Post by mcc »

I built snes9x master myself and did some minimal debugging. I discovered the freeze is happening on this line. The "Sync Sound" feature, if enabled, waits for 1 second for an event from the audio thread. However it appears the audio thread has exited or otherwise is no longer emitting the event. The wait is on the main thread so the GUI thread will be pausing for 1 full second every tick of the event loop.

This means there is a workaround if you are encountering the problem: Disable "Sync Sound" in the Sound menu before you begin playing. On my system if I do this then plug or unplug headphones the audio goes away permanently, but the game does not freeze.

The fix for this bug appears to be
1. Figure out why the Audio thread exits/hangs/stops emitting GUI.SoundSyncEvent on audio device changes, and make it not do that
2. Though this would not be *necessary* to fix the bug, it would probably be smart to make that WaitForSingleObject(GUI.SoundSyncEvent) somehow more tolerant of / able to detect failures in the audio thread. For example if the 1 second timeout happens twice in a row, it could automatically disable sync sound until the audio thread comes back.
WKRPinNJ
Snes9x White Belt
Posts: 3
Joined: Thu Mar 26, 2020 11:00 am

Re: Switching Audio Input Source Crashes Snes9x (Windows 10)

Post by WKRPinNJ »

MCC,

Thank you. Turning off Sync Sound seems to have done the trick for now.

Please keep us updated as to when the problem has been fixed, so us "headphone/audio source" switchers can use the feature again.

Much appreciated.
WKRPinNJ
Snes9x White Belt
Posts: 3
Joined: Thu Mar 26, 2020 11:00 am

Re: Switching Audio Input Source Crashes Snes9x (Windows 10)

Post by WKRPinNJ »

Upon further use, the problem is still happening from time to time with Sync Sound turned off, just not as often.

In my case, I'm using a 4K TV as a monitor, and it seems to freeze Snes9x when switching HDMI inputs. There could be other situations, such as switching headphones (that happened to me once) as this observation is probably preliminary without more testing tools.
Post Reply