summaryrefslogtreecommitdiff
path: root/src/sound
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-09-11 15:09:12 +0200
committerMichael Lutz <michi@icosahedron.de>2021-09-11 15:42:34 +0200
commitee57afc285f277d30cd3c87f6bcea2bb60b3e0f6 (patch)
treea52d2ae4de62aa6c6c40ef855397965c056d5183 /src/sound
parenta8641ea44a9c218a57abe84be7f38f0e19834bb3 (diff)
downloadopenttd-ee57afc285f277d30cd3c87f6bcea2bb60b3e0f6.tar.xz
Fix #9463: [Win32] Try to work around XAudio2 crashes by catching SEH exceptions.
If an exceptions is thrown during context creation, just declare the XAudio driver as unusable. The driver logic will try to find an alternative for us.
Diffstat (limited to 'src/sound')
-rw-r--r--src/sound/xaudio2_s.cpp17
1 files changed, 15 insertions, 2 deletions
diff --git a/src/sound/xaudio2_s.cpp b/src/sound/xaudio2_s.cpp
index dd66c8aef..70f8fa987 100644
--- a/src/sound/xaudio2_s.cpp
+++ b/src/sound/xaudio2_s.cpp
@@ -117,6 +117,20 @@ static IXAudio2MasteringVoice* _mastering_voice = nullptr;
static ComPtr<IXAudio2> _xaudio2;
static StreamingVoiceContext* _voice_context = nullptr;
+/** Create XAudio2 context with SEH exception checking. */
+static HRESULT CreateXAudio(API_XAudio2Create xAudio2Create)
+{
+ HRESULT hr;
+ __try {
+ UINT32 flags = 0;
+ hr = xAudio2Create(_xaudio2.GetAddressOf(), flags, XAUDIO2_DEFAULT_PROCESSOR);
+ } __except (EXCEPTION_EXECUTE_HANDLER) {
+ hr = GetExceptionCode();
+ }
+
+ return hr;
+}
+
/**
* Initialises the XAudio2 driver.
*
@@ -156,8 +170,7 @@ const char *SoundDriver_XAudio2::Start(const StringList &parm)
}
// Create the XAudio engine
- UINT32 flags = 0;
- hr = xAudio2Create(_xaudio2.GetAddressOf(), flags, XAUDIO2_DEFAULT_PROCESSOR);
+ hr = CreateXAudio(xAudio2Create);
if (FAILED(hr))
{