Fix audio dialog crash when audio device doesn't exist

This commit is contained in:
RadWolfie 2018-07-07 12:01:19 -05:00
parent 56bbfe7586
commit 736813fae1
1 changed files with 13 additions and 4 deletions

View File

@ -211,17 +211,26 @@ VOID RefreshAudioAdapter()
GUID binGUID; GUID binGUID;
if (pGUID) { // Check if pGUID doesn't have CB_ERR. (source of cause to crash)
if (pGUID != nullptr && pGUID != (LPGUID)CB_ERR) {
binGUID = *pGUID; binGUID = *pGUID;
} else { }
else {
binGUID = { 0 }; binGUID = { 0 };
} }
if(binGUID != oldGUID) if(binGUID != oldGUID) {
{
g_bHasChanges = TRUE; g_bHasChanges = TRUE;
g_XBAudio.SetAudioAdapter(binGUID); g_XBAudio.SetAudioAdapter(binGUID);
} }
// Force save default audio device if selected audo device is invalid.
if (pGUID == (LPGUID)CB_ERR) {
SendMessage(g_hAudioAdapter, CB_SETCURSEL, 0, 0);
g_EmuShared->SetXBAudio(&g_XBAudio);
MessageBox(nullptr, "Your selected audio device is invalid,\n"
"reverting to default audio device.", "Cxbx-Reloaded", MB_OK | MB_ICONEXCLAMATION);
}
} }
} }