Changeset - r25951:4738613420a3
[Not reviewed]
master
0 1 0
Michael Lutz - 3 years ago 2021-09-11 13:09:12
michi@icosahedron.de
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.
1 file changed with 15 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/sound/xaudio2_s.cpp
Show inline comments
 
@@ -114,12 +114,26 @@ public:
 
static HMODULE _xaudio_dll_handle;
 
static IXAudio2SourceVoice* _source_voice = nullptr;
 
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.
 
*
 
* @param parm Driver parameters.
 
* @return An error message if unsuccessful, or nullptr otherwise.
 
*
 
@@ -153,14 +167,13 @@ const char *SoundDriver_XAudio2::Start(c
 

	
 
		Debug(driver, 0, "xaudio2_s: Unable to find XAudio2Create function in DLL");
 
		return "Failed to load XAudio2 DLL";
 
	}
 

	
 
	// Create the XAudio engine
 
	UINT32 flags = 0;
 
	hr = xAudio2Create(_xaudio2.GetAddressOf(), flags, XAUDIO2_DEFAULT_PROCESSOR);
 
	hr = CreateXAudio(xAudio2Create);
 

	
 
	if (FAILED(hr))
 
	{
 
		FreeLibrary(_xaudio_dll_handle);
 
		CoUninitialize();
 

	
0 comments (0 inline, 0 general)