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:
parent
35f0a47938
commit
59b602fb96
1 changed files with 12 additions and 2 deletions
|
@ -39,24 +39,34 @@ namespace Ryujinx.Audio
|
||||||
SoundIO context = null;
|
SoundIO context = null;
|
||||||
SoundIODevice device = null;
|
SoundIODevice device = null;
|
||||||
SoundIOOutStream stream = null;
|
SoundIOOutStream stream = null;
|
||||||
|
bool backendDisconnected = false;
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
context = new SoundIO();
|
context = new SoundIO();
|
||||||
|
|
||||||
|
context.OnBackendDisconnect = (i) => {
|
||||||
|
backendDisconnected = true;
|
||||||
|
};
|
||||||
|
|
||||||
context.Connect();
|
context.Connect();
|
||||||
context.FlushEvents();
|
context.FlushEvents();
|
||||||
|
|
||||||
|
if(backendDisconnected)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
device = context.GetOutputDevice(context.DefaultOutputDeviceIndex);
|
device = context.GetOutputDevice(context.DefaultOutputDeviceIndex);
|
||||||
|
|
||||||
if(device == null)
|
if(device == null || backendDisconnected)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stream = device.CreateOutStream();
|
stream = device.CreateOutStream();
|
||||||
|
|
||||||
if(stream == null)
|
if(stream == null || backendDisconnected)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue