Merge pull request #1337 from RadWolfie/fix-audio-device-crash
Fix invalid audio adapter crash
This commit is contained in:
commit
46f3086ed9
|
@ -211,17 +211,26 @@ VOID RefreshAudioAdapter()
|
|||
|
||||
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;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
binGUID = { 0 };
|
||||
}
|
||||
|
||||
if(binGUID != oldGUID)
|
||||
{
|
||||
if(binGUID != oldGUID) {
|
||||
g_bHasChanges = TRUE;
|
||||
|
||||
g_XBAudio.SetAudioAdapter(binGUID);
|
||||
}
|
||||
|
||||
// Force save default audio device if selected audio 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 adapter is invalid,\n"
|
||||
"reverting to default audio adapter.", "Cxbx-Reloaded", MB_OK | MB_ICONEXCLAMATION);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -271,8 +271,38 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate)
|
|||
if (!initialized || g_pDSound8 == nullptr) {
|
||||
hRet = DirectSoundCreate8(&g_XBAudio.GetAudioAdapter(), &g_pDSound8, NULL);
|
||||
|
||||
if (hRet != DS_OK) {
|
||||
CxbxKrnlCleanup("DirectSoundCreate8 Failed!");
|
||||
LPCSTR dsErrorMsg = nullptr;
|
||||
|
||||
switch (hRet) {
|
||||
case DS_OK:
|
||||
// Is not a fatal error.
|
||||
break;
|
||||
case DSERR_ALLOCATED:
|
||||
dsErrorMsg = "Audio adapter is already allocated. Possible fault within Cxbx-Reloaded's emulator."
|
||||
"\n\nPlease report to respective game compatibility issue.";
|
||||
break;
|
||||
case DSERR_INVALIDPARAM:
|
||||
dsErrorMsg = "DirectSoundCreate8 return invalid parameter."
|
||||
"\n\nPlease report to respective game compatibility issue.";
|
||||
break;
|
||||
case DSERR_NOAGGREGATION:
|
||||
dsErrorMsg = "Audio adapter does not support aggregation."
|
||||
"\n\nPlease use different audio adapter.";
|
||||
break;
|
||||
case DSERR_NODRIVER:
|
||||
dsErrorMsg = "Please select a valid audio adapter from Cxbx-Reloaded's config audio dialog."
|
||||
"\n\nThen try again.";
|
||||
break;
|
||||
case DSERR_OUTOFMEMORY:
|
||||
dsErrorMsg = "Unable to allocate DirectSound subsystem class."
|
||||
"\n\nPlease close any opened application(s) or restart computer before trying again.";
|
||||
break;
|
||||
default:
|
||||
dsErrorMsg = "DirectSoundCreate8 unknown failed: 0x%08X";
|
||||
}
|
||||
|
||||
if (dsErrorMsg != nullptr) {
|
||||
CxbxKrnlCleanup(dsErrorMsg, hRet);
|
||||
}
|
||||
|
||||
hRet = g_pDSound8->SetCooperativeLevel(g_hEmuWindow, DSSCL_PRIORITY);
|
||||
|
|
Loading…
Reference in New Issue