From 000f4984cfda9534e629094aa8efc24b7aeacc03 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Fri, 20 Nov 2015 21:48:28 +0000 Subject: [PATCH] spu2-x:windows: Potentially prevent XAudio2.7 unload crashes The extra LoadLibrary call prevents XAudio2.7 from unloading since LoadLibrary reference counts. See http://blogs.msdn.com/b/chuckw/archive/2015/10/09/known-issues-xaudio-2-7.aspx Should fix random XAudio2 crashes. --- plugins/spu2-x/src/Windows/SndOut_XAudio2.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/plugins/spu2-x/src/Windows/SndOut_XAudio2.cpp b/plugins/spu2-x/src/Windows/SndOut_XAudio2.cpp index 9dc1c0e885..73ebf918bb 100644 --- a/plugins/spu2-x/src/Windows/SndOut_XAudio2.cpp +++ b/plugins/spu2-x/src/Windows/SndOut_XAudio2.cpp @@ -233,6 +233,7 @@ private: }; + HMODULE xAudio2DLL; CComPtr pXAudio2; IXAudio2MasteringVoice* pMasteringVoice; BaseStreamingVoice* voiceContext; @@ -245,6 +246,16 @@ public: jASSUME( pXAudio2 == NULL ); + // On some systems XAudio2.7 can unload itself and cause PCSX2 to crash. + // Maintain an extra library reference so it can't do so. Does not + // affect XAudio 2.8+, but that's Win8+. See + // http://blogs.msdn.com/b/chuckw/archive/2015/10/09/known-issues-xaudio-2-7.aspx +#ifdef _DEBUG + xAudio2DLL = LoadLibrary(L"XAudioD2_7.dll"); +#else + xAudio2DLL = LoadLibrary(L"XAudio2_7.dll"); +#endif + // // Initialize XAudio2 // @@ -375,6 +386,11 @@ public: pXAudio2.Release(); CoUninitialize(); + + if (xAudio2DLL) { + FreeLibrary(xAudio2DLL); + xAudio2DLL = nullptr; + } } virtual void Configure(uptr parent)