Skip to content

Commit

Permalink
Merge pull request Cxbx-Reloaded#1337 from RadWolfie/fix-audio-device…
Browse files Browse the repository at this point in the history
…-crash

Fix invalid audio adapter crash
  • Loading branch information
RadWolfie authored Jul 8, 2018
2 parents 56bbfe7 + 31f0cc4 commit 46f3086
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
17 changes: 13 additions & 4 deletions src/Cxbx/DlgAudioConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
34 changes: 32 additions & 2 deletions src/CxbxKrnl/EmuDSound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 46f3086

Please sign in to comment.