From 736813fae194b8381aec1d0450fdacdf25db84e5 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Sat, 7 Jul 2018 12:01:19 -0500 Subject: [PATCH 1/7] Fix audio dialog crash when audio device doesn't exist --- src/Cxbx/DlgAudioConfig.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Cxbx/DlgAudioConfig.cpp b/src/Cxbx/DlgAudioConfig.cpp index 0ad641c66a..315edcb76f 100644 --- a/src/Cxbx/DlgAudioConfig.cpp +++ b/src/Cxbx/DlgAudioConfig.cpp @@ -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 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); + } } } From adec56846a17d50d7b04d0f86263bd46d0d3376c Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Sat, 7 Jul 2018 12:07:22 -0500 Subject: [PATCH 2/7] Extend a message for request user to select a valid audio device on emulator side. --- src/CxbxKrnl/EmuDSound.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CxbxKrnl/EmuDSound.cpp b/src/CxbxKrnl/EmuDSound.cpp index 7ccd46b973..792ed871f0 100755 --- a/src/CxbxKrnl/EmuDSound.cpp +++ b/src/CxbxKrnl/EmuDSound.cpp @@ -272,7 +272,8 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) hRet = DirectSoundCreate8(&g_XBAudio.GetAudioAdapter(), &g_pDSound8, NULL); if (hRet != DS_OK) { - CxbxKrnlCleanup("DirectSoundCreate8 Failed!"); + CxbxKrnlCleanup("DirectSoundCreate8 Failed!" + "\n\nPlease select a valid audio device from Cxbx-Reloaded's config audio dialog."); } hRet = g_pDSound8->SetCooperativeLevel(g_hEmuWindow, DSSCL_PRIORITY); From 223500f4fb2bfe2060f70788ca6bf726f374491d Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Sat, 7 Jul 2018 12:28:08 -0500 Subject: [PATCH 3/7] Fix typo --- src/Cxbx/DlgAudioConfig.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cxbx/DlgAudioConfig.cpp b/src/Cxbx/DlgAudioConfig.cpp index 315edcb76f..3fb5252dbf 100644 --- a/src/Cxbx/DlgAudioConfig.cpp +++ b/src/Cxbx/DlgAudioConfig.cpp @@ -225,7 +225,7 @@ VOID RefreshAudioAdapter() g_XBAudio.SetAudioAdapter(binGUID); } - // Force save default audio device if selected audo device is invalid. + // 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); From 8744a25f86b335763e95d7962454f74761a7286b Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Sat, 7 Jul 2018 16:00:47 -0500 Subject: [PATCH 4/7] Expand DirectSoundCreate error messages. --- src/CxbxKrnl/EmuDSound.cpp | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/src/CxbxKrnl/EmuDSound.cpp b/src/CxbxKrnl/EmuDSound.cpp index 792ed871f0..083775081b 100755 --- a/src/CxbxKrnl/EmuDSound.cpp +++ b/src/CxbxKrnl/EmuDSound.cpp @@ -271,9 +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!" - "\n\nPlease select a valid audio device from Cxbx-Reloaded's config audio dialog."); + LPCSTR dsErrorMsg = nullptr; + + switch (hRet) { + case DS_OK: + // Is not a fatal error. + break; + case DSERR_ALLOCATED: + dsErrorMsg = "Audio device 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 paramemter." + "\n\nPlease report to respective game compatibility issue."; + break; + case DSERR_NOAGGREGATION: + dsErrorMsg = "Audio device does not support aggregation." + "\n\nPlease use different audio device."; + break; + case DSERR_NODRIVER: + dsErrorMsg = "Please select a valid audio device from Cxbx-Reloaded's config audio dialog." + "\n\nThen try again."; + break; + case DSERR_OUTOFMEMORY: + dsErrorMsg = "Unable to allocate DirectSound subystem class." + "\n\nPlease close any opened applications or restart computer before try again."; + break; + default: + dsErrorMsg = "DirectSoundCreate8 unknown failed: 0x%08X"; + } + + if (dsErrorMsg != nullptr) { + CxbxKrnlCleanup(dsErrorMsg, hRet); } hRet = g_pDSound8->SetCooperativeLevel(g_hEmuWindow, DSSCL_PRIORITY); From e6987af8990a407f894221452af4cc78aab45bf1 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Sat, 7 Jul 2018 16:10:25 -0500 Subject: [PATCH 5/7] Another fix for typos --- src/CxbxKrnl/EmuDSound.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/CxbxKrnl/EmuDSound.cpp b/src/CxbxKrnl/EmuDSound.cpp index 083775081b..da7269409d 100755 --- a/src/CxbxKrnl/EmuDSound.cpp +++ b/src/CxbxKrnl/EmuDSound.cpp @@ -282,7 +282,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) "\n\nPlease report to respective game compatibility issue."; break; case DSERR_INVALIDPARAM: - dsErrorMsg = "DirectSoundCreate8 return invalid paramemter." + dsErrorMsg = "DirectSoundCreate8 return invalid parameter." "\n\nPlease report to respective game compatibility issue."; break; case DSERR_NOAGGREGATION: @@ -294,8 +294,8 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) "\n\nThen try again."; break; case DSERR_OUTOFMEMORY: - dsErrorMsg = "Unable to allocate DirectSound subystem class." - "\n\nPlease close any opened applications or restart computer before try again."; + dsErrorMsg = "Unable to allocate DirectSound subsystem class." + "\n\nPlease close any opened application(s) or restart computer before try again."; break; default: dsErrorMsg = "DirectSoundCreate8 unknown failed: 0x%08X"; From 8e84fdf7f5f9788a94f6510c845c2344bd937025 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Sat, 7 Jul 2018 16:41:40 -0500 Subject: [PATCH 6/7] Replace device to adapter keyword --- src/Cxbx/DlgAudioConfig.cpp | 4 ++-- src/CxbxKrnl/EmuDSound.cpp | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Cxbx/DlgAudioConfig.cpp b/src/Cxbx/DlgAudioConfig.cpp index 3fb5252dbf..0509ef6272 100644 --- a/src/Cxbx/DlgAudioConfig.cpp +++ b/src/Cxbx/DlgAudioConfig.cpp @@ -229,8 +229,8 @@ VOID RefreshAudioAdapter() 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); + MessageBox(nullptr, "Your selected audio adapter is invalid,\n" + "reverting to default audio adapter.", "Cxbx-Reloaded", MB_OK | MB_ICONEXCLAMATION); } } } diff --git a/src/CxbxKrnl/EmuDSound.cpp b/src/CxbxKrnl/EmuDSound.cpp index da7269409d..482dd8a871 100755 --- a/src/CxbxKrnl/EmuDSound.cpp +++ b/src/CxbxKrnl/EmuDSound.cpp @@ -278,7 +278,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) // Is not a fatal error. break; case DSERR_ALLOCATED: - dsErrorMsg = "Audio device is already allocated. Possible fault within Cxbx-Reloaded's emulator." + 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: @@ -286,11 +286,11 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) "\n\nPlease report to respective game compatibility issue."; break; case DSERR_NOAGGREGATION: - dsErrorMsg = "Audio device does not support aggregation." - "\n\nPlease use different audio device."; + dsErrorMsg = "Audio adapter does not support aggregation." + "\n\nPlease use different audio adapter."; break; case DSERR_NODRIVER: - dsErrorMsg = "Please select a valid audio device from Cxbx-Reloaded's config audio dialog." + dsErrorMsg = "Please select a valid audio adapter from Cxbx-Reloaded's config audio dialog." "\n\nThen try again."; break; case DSERR_OUTOFMEMORY: From 31f0cc4a9bf6347bb2e01c2e066e658aff6a0aa1 Mon Sep 17 00:00:00 2001 From: RadWolfie Date: Sat, 7 Jul 2018 17:39:04 -0500 Subject: [PATCH 7/7] grammar fix Co-Authored-By: Eurose --- src/CxbxKrnl/EmuDSound.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CxbxKrnl/EmuDSound.cpp b/src/CxbxKrnl/EmuDSound.cpp index 482dd8a871..1837ad5c0b 100755 --- a/src/CxbxKrnl/EmuDSound.cpp +++ b/src/CxbxKrnl/EmuDSound.cpp @@ -295,7 +295,7 @@ HRESULT WINAPI XTL::EMUPATCH(DirectSoundCreate) break; case DSERR_OUTOFMEMORY: dsErrorMsg = "Unable to allocate DirectSound subsystem class." - "\n\nPlease close any opened application(s) or restart computer before try again."; + "\n\nPlease close any opened application(s) or restart computer before trying again."; break; default: dsErrorMsg = "DirectSoundCreate8 unknown failed: 0x%08X";