Audio: Handle the backend disconnected event

libsoundio panics by default when a backend disconnects, this catches that event and gracefully handles it.
This commit is contained in:
jduncanator 2018-11-17 08:59:31 +11:00
parent 35f0a47938
commit 59b602fb96

View file

@ -39,24 +39,34 @@ namespace Ryujinx.Audio
SoundIO context = null;
SoundIODevice device = null;
SoundIOOutStream stream = null;
bool backendDisconnected = false;
try
{
context = new SoundIO();
context.OnBackendDisconnect = (i) => {
backendDisconnected = true;
};
context.Connect();
context.FlushEvents();
if(backendDisconnected)
{
return false;
}
device = context.GetOutputDevice(context.DefaultOutputDeviceIndex);
if(device == null)
if(device == null || backendDisconnected)
{
return false;
}
stream = device.CreateOutStream();
if(stream == null)
if(stream == null || backendDisconnected)
{
return false;
}