From e68258e56e78b967a45a36be89a82b1d75a2835b Mon Sep 17 00:00:00 2001 From: kervala Date: Fri, 16 Sep 2016 19:25:17 +0200 Subject: [PATCH] Merge with develop --- code/nel/src/misc/system_utils.cpp | 20 +++++++++++++--- .../tools/client/ryzom_installer/src/main.cpp | 23 +++++++++++++++++-- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/code/nel/src/misc/system_utils.cpp b/code/nel/src/misc/system_utils.cpp index 81bb5246b..480e1c9a1 100644 --- a/code/nel/src/misc/system_utils.cpp +++ b/code/nel/src/misc/system_utils.cpp @@ -76,12 +76,21 @@ namespace NLMISC { nlWindow CSystemUtils::s_window = EmptyWindow; +#ifdef NL_OS_WINDOWS +static bool s_mustUninit = false; +#endif + bool CSystemUtils::init() { #ifdef NL_OS_WINDOWS // initialize COM - HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); - if (FAILED(hr)) return false; + if (!s_mustUninit) + { + HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED); + if (FAILED(hr)) return false; + + s_mustUninit = true; + } #endif return true; @@ -91,7 +100,12 @@ bool CSystemUtils::uninit() { #ifdef NL_OS_WINDOWS // uninitialize COM - CoUninitialize(); + if (s_mustUninit) + { + CoUninitialize(); + + s_mustUninit = false; + } #endif return true; diff --git a/code/ryzom/tools/client/ryzom_installer/src/main.cpp b/code/ryzom/tools/client/ryzom_installer/src/main.cpp index 3d7ee1d1c..da1ec1c1d 100644 --- a/code/ryzom/tools/client/ryzom_installer/src/main.cpp +++ b/code/ryzom/tools/client/ryzom_installer/src/main.cpp @@ -80,6 +80,26 @@ bool copyInstallerFiles(const QStringList &files, const QString &destination) return true; } +#ifdef Q_OS_WIN +class CCOMHelper +{ + bool m_mustUninit; + +public: + CCOMHelper() + { + // to fix the bug with QFileDialog::getExistingDirectory hanging under Windows + m_mustUninit = SUCCEEDED(CoInitialize(NULL)); + } + + ~CCOMHelper() + { + // only call CoUninitialize if CoInitialize succeeded + if (m_mustUninit) CoUninitialize(); + } +}; +#endif + int main(int argc, char *argv[]) { #if defined(_MSC_VER) && defined(_DEBUG) @@ -87,8 +107,7 @@ int main(int argc, char *argv[]) #endif #ifdef Q_OS_WIN - // to fix the bug with QFileDialog::getExistingDirectory hanging under Windows - CoInitialize(NULL); + CCOMHelper comHelper; #endif NLMISC::CApplicationContext appContext;