Windows: Fix file and folder dialog freeze (#369)

Initializing the COM library immediately seems to be more robust than doing it on demand
This commit is contained in:
Exzap 2022-10-14 12:49:41 +02:00 committed by GitHub
parent d251ce07e0
commit a19ed46b2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 7 additions and 47 deletions

View File

@ -167,25 +167,11 @@ void CubebAPI::SetVolume(sint32 volume)
bool CubebAPI::InitializeStatic() bool CubebAPI::InitializeStatic()
{ {
#if BOOST_OS_WINDOWS
s_com_initialized = (SUCCEEDED(CoInitializeEx(nullptr, COINIT_MULTITHREADED)));
#endif
if (cubeb_init(&s_context, "Cemu Cubeb", nullptr)) if (cubeb_init(&s_context, "Cemu Cubeb", nullptr))
{ {
cemuLog_force("can't create cubeb audio api"); cemuLog_force("can't create cubeb audio api");
#if BOOST_OS_WINDOWS
if (s_com_initialized)
{
CoUninitialize();
s_com_initialized = false;
}
#endif
return false; return false;
} }
return true; return true;
} }
@ -193,10 +179,6 @@ void CubebAPI::Destroy()
{ {
if (s_context) if (s_context)
cubeb_destroy(s_context); cubeb_destroy(s_context);
#if BOOST_OS_WINDOWS
if (s_com_initialized)
CoUninitialize();
#endif
} }
std::vector<IAudioAPI::DeviceDescriptionPtr> CubebAPI::GetDevices() std::vector<IAudioAPI::DeviceDescriptionPtr> CubebAPI::GetDevices()

View File

@ -41,7 +41,6 @@ public:
static void Destroy(); static void Destroy();
private: private:
inline static bool s_com_initialized = false;
inline static cubeb* s_context = nullptr; inline static cubeb* s_context = nullptr;
cubeb_stream* m_stream = nullptr; cubeb_stream* m_stream = nullptr;

View File

@ -5,7 +5,6 @@
static_assert(IAudioAPI::kBlockCount < XAUDIO2_MAX_QUEUED_BUFFERS, "too many xaudio2 buffers"); static_assert(IAudioAPI::kBlockCount < XAUDIO2_MAX_QUEUED_BUFFERS, "too many xaudio2 buffers");
HMODULE XAudio27API::s_xaudio_dll = nullptr; HMODULE XAudio27API::s_xaudio_dll = nullptr;
bool XAudio27API::s_com_initialized = false;
std::unique_ptr<IXAudio2, XAudio27API::XAudioDeleter> XAudio27API::s_xaudio; std::unique_ptr<IXAudio2, XAudio27API::XAudioDeleter> XAudio27API::s_xaudio;
XAudio27API::XAudio27API(uint32 device_id, uint32 samplerate, uint32 channels, uint32 samples_per_block, uint32 bits_per_sample) XAudio27API::XAudio27API(uint32 device_id, uint32 samplerate, uint32 channels, uint32 samples_per_block, uint32 bits_per_sample)
@ -115,8 +114,6 @@ bool XAudio27API::InitializeStatic()
if (s_xaudio) if (s_xaudio)
return true; return true;
s_com_initialized = (SUCCEEDED(CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE)));
#ifdef _DEBUG #ifdef _DEBUG
s_xaudio_dll = LoadLibraryExW(L"XAudioD2_7.DLL", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); s_xaudio_dll = LoadLibraryExW(L"XAudioD2_7.DLL", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
if(!s_xaudio_dll) if(!s_xaudio_dll)
@ -142,9 +139,6 @@ bool XAudio27API::InitializeStatic()
if (s_xaudio_dll) if (s_xaudio_dll)
FreeLibrary(s_xaudio_dll); FreeLibrary(s_xaudio_dll);
if (s_com_initialized)
CoUninitialize();
return false; return false;
} }
} }
@ -155,9 +149,6 @@ void XAudio27API::Destroy()
if (s_xaudio_dll) if (s_xaudio_dll)
FreeLibrary(s_xaudio_dll); FreeLibrary(s_xaudio_dll);
if (s_com_initialized)
CoUninitialize();
} }
std::vector<XAudio27API::DeviceDescriptionPtr> XAudio27API::GetDevices() std::vector<XAudio27API::DeviceDescriptionPtr> XAudio27API::GetDevices()

View File

@ -58,7 +58,6 @@ private:
}; };
static HMODULE s_xaudio_dll; static HMODULE s_xaudio_dll;
static bool s_com_initialized;
static std::unique_ptr<IXAudio2, XAudioDeleter> s_xaudio; static std::unique_ptr<IXAudio2, XAudioDeleter> s_xaudio;
std::unique_ptr<IXAudio2, XAudioDeleter> m_xaudio; std::unique_ptr<IXAudio2, XAudioDeleter> m_xaudio;

View File

@ -23,7 +23,6 @@ static const GUID DEVINTERFACE_AUDIO_RENDER_GUID = { 0xe6327cad, 0xdcec, 0x4949,
static_assert(IAudioAPI::kBlockCount < XAUDIO2_MAX_QUEUED_BUFFERS, "too many xaudio2 buffers"); static_assert(IAudioAPI::kBlockCount < XAUDIO2_MAX_QUEUED_BUFFERS, "too many xaudio2 buffers");
HMODULE XAudio2API::s_xaudio_dll = nullptr; HMODULE XAudio2API::s_xaudio_dll = nullptr;
bool XAudio2API::s_com_initialized = false;
std::vector<XAudio2API::DeviceDescriptionPtr> XAudio2API::s_devices; std::vector<XAudio2API::DeviceDescriptionPtr> XAudio2API::s_devices;
XAudio2API::XAudio2API(std::wstring device_id, uint32 samplerate, uint32 channels, uint32 samples_per_block, uint32 bits_per_sample) XAudio2API::XAudio2API(std::wstring device_id, uint32 samplerate, uint32 channels, uint32 samples_per_block, uint32 bits_per_sample)
@ -144,8 +143,6 @@ bool XAudio2API::InitializeStatic()
if (s_xaudio_dll) if (s_xaudio_dll)
return true; return true;
s_com_initialized = (SUCCEEDED(CoInitializeEx(nullptr, COINIT_MULTITHREADED)));
// win 10 // win 10
s_xaudio_dll = LoadLibraryEx(XAUDIO2_DLL, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32); s_xaudio_dll = LoadLibraryEx(XAUDIO2_DLL, nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
@ -166,9 +163,6 @@ bool XAudio2API::InitializeStatic()
if (s_xaudio_dll) if (s_xaudio_dll)
FreeLibrary(s_xaudio_dll); FreeLibrary(s_xaudio_dll);
if (s_com_initialized)
CoUninitialize();
return false; return false;
} }
} }
@ -177,20 +171,12 @@ void XAudio2API::Destroy()
{ {
if (s_xaudio_dll) if (s_xaudio_dll)
FreeLibrary(s_xaudio_dll); FreeLibrary(s_xaudio_dll);
if (s_com_initialized)
CoUninitialize();
} }
const std::vector<XAudio2API::DeviceDescriptionPtr>& XAudio2API::RefreshDevices() const std::vector<XAudio2API::DeviceDescriptionPtr>& XAudio2API::RefreshDevices()
{ {
// this function must be called from the same thread as we called CoInitializeEx
s_devices.clear(); s_devices.clear();
HRESULT r = CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE);
if (r != RPC_E_CHANGED_MODE && FAILED(r))
return s_devices;
try try
{ {
struct IWbemLocator *wbem_locator = nullptr; struct IWbemLocator *wbem_locator = nullptr;

View File

@ -59,7 +59,6 @@ private:
}; };
static HMODULE s_xaudio_dll; static HMODULE s_xaudio_dll;
static bool s_com_initialized;
static std::vector<DeviceDescriptionPtr> s_devices; static std::vector<DeviceDescriptionPtr> s_devices;
std::unique_ptr<IXAudio2, XAudioDeleter> m_xaudio; std::unique_ptr<IXAudio2, XAudioDeleter> m_xaudio;

View File

@ -323,7 +323,7 @@ void HandlePostUpdate()
fs::remove(filename, ec); fs::remove(filename, ec);
} }
#else #else
while( fs::exists(filename) ) while (fs::exists(filename))
{ {
std::error_code ec; std::error_code ec;
fs::remove(filename, ec); fs::remove(filename, ec);
@ -338,8 +338,10 @@ void ToolShaderCacheMerger();
#if BOOST_OS_WINDOWS #if BOOST_OS_WINDOWS
// entrypoint for release builds // entrypoint for release builds
int wWinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nShowCmd) int wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ LPTSTR lpCmdLine, _In_ int nShowCmd)
{ {
if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE)))
cemuLog_log(LogType::Force, "CoInitializeEx() failed");
SDL_SetMainReady(); SDL_SetMainReady();
if (!LaunchSettings::HandleCommandline(lpCmdLine)) if (!LaunchSettings::HandleCommandline(lpCmdLine))
return 0; return 0;
@ -350,6 +352,8 @@ int wWinMain( _In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, _In_ L
// entrypoint for debug builds with console // entrypoint for debug builds with console
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {
if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED | COINIT_DISABLE_OLE1DDE)))
cemuLog_log(LogType::Force, "CoInitializeEx() failed");
SDL_SetMainReady(); SDL_SetMainReady();
if (!LaunchSettings::HandleCommandline(argc, argv)) if (!LaunchSettings::HandleCommandline(argc, argv))
return 0; return 0;