From d3da20d63f6ddf6f3760208d7db130d15860e852 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 22 Nov 2023 01:01:12 +0200 Subject: SL-20603 Crash on CoInitialize Don't mix CoInitialize and CoInitializeEx, one is global, other is threaded. CoInitialize(0) is equal to CoInitializeEx(0, COINIT_APARTMENTTHREADED) and MULTITHREADED is not compatible with APARTMENTTHREADED. --- indra/llwindow/lldxhardware.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/llwindow/lldxhardware.cpp') diff --git a/indra/llwindow/lldxhardware.cpp b/indra/llwindow/lldxhardware.cpp index 391a377280..07856edefc 100644 --- a/indra/llwindow/lldxhardware.cpp +++ b/indra/llwindow/lldxhardware.cpp @@ -71,7 +71,7 @@ HRESULT GetVideoMemoryViaWMI(WCHAR* strInputDeviceID, DWORD* pdwAdapterRam) BSTR pNamespace = nullptr; *pdwAdapterRam = 0; - hrCoInitialize = CoInitialize( 0 ); + hrCoInitialize = CoInitializeEx(0, COINIT_MULTITHREADED); hr = CoCreateInstance( CLSID_WbemLocator, nullptr, @@ -234,7 +234,7 @@ std::string LLDXHardware::getDriverVersionWMI(EGPUVendor vendor) std::string mDriverVersion; HRESULT hrCoInitialize = S_OK; HRESULT hres; - hrCoInitialize = CoInitialize(0); + hrCoInitialize = CoInitializeEx(0, COINIT_MULTITHREADED); IWbemLocator *pLoc = NULL; hres = CoCreateInstance( @@ -687,7 +687,7 @@ BOOL LLDXHardware::getInfo(BOOL vram_only) BOOL ok = FALSE; HRESULT hr; - CoInitialize(NULL); + CoInitializeEx(NULL, COINIT_MULTITHREADED); IDxDiagProvider *dx_diag_providerp = NULL; IDxDiagContainer *dx_diag_rootp = NULL; @@ -976,7 +976,7 @@ LLSD LLDXHardware::getDisplayInfo() LLTimer hw_timer; HRESULT hr; LLSD ret; - CoInitialize(NULL); + CoInitializeEx(NULL, COINIT_MULTITHREADED); IDxDiagProvider *dx_diag_providerp = NULL; IDxDiagContainer *dx_diag_rootp = NULL; -- cgit v1.2.3 From 5accc1feff322c89e63fbfa0f3ac6911abcf6436 Mon Sep 17 00:00:00 2001 From: Andrey Kleshchev Date: Wed, 6 Dec 2023 12:58:20 +0200 Subject: SL-20695 Fix hardware probes CoCreateInstance returns 'no interface supported' Preferable not to mix init types so switched everything. --- indra/llwindow/lldxhardware.cpp | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'indra/llwindow/lldxhardware.cpp') diff --git a/indra/llwindow/lldxhardware.cpp b/indra/llwindow/lldxhardware.cpp index 07856edefc..aaa2f6aef1 100644 --- a/indra/llwindow/lldxhardware.cpp +++ b/indra/llwindow/lldxhardware.cpp @@ -65,13 +65,12 @@ HRESULT GetVideoMemoryViaWMI(WCHAR* strInputDeviceID, DWORD* pdwAdapterRam) { HRESULT hr; bool bGotMemory = false; - HRESULT hrCoInitialize = S_OK; IWbemLocator* pIWbemLocator = nullptr; IWbemServices* pIWbemServices = nullptr; BSTR pNamespace = nullptr; *pdwAdapterRam = 0; - hrCoInitialize = CoInitializeEx(0, COINIT_MULTITHREADED); + CoInitializeEx(0, COINIT_APARTMENTTHREADED); hr = CoCreateInstance( CLSID_WbemLocator, nullptr, @@ -208,8 +207,7 @@ HRESULT GetVideoMemoryViaWMI(WCHAR* strInputDeviceID, DWORD* pdwAdapterRam) SAFE_RELEASE( pIWbemLocator ); - if( SUCCEEDED( hrCoInitialize ) ) - CoUninitialize(); + CoUninitialize(); if( bGotMemory ) return S_OK; @@ -232,9 +230,8 @@ S32 LLDXHardware::getMBVideoMemoryViaWMI() std::string LLDXHardware::getDriverVersionWMI(EGPUVendor vendor) { std::string mDriverVersion; - HRESULT hrCoInitialize = S_OK; HRESULT hres; - hrCoInitialize = CoInitializeEx(0, COINIT_MULTITHREADED); + CoInitializeEx(0, COINIT_APARTMENTTHREADED); IWbemLocator *pLoc = NULL; hres = CoCreateInstance( @@ -437,10 +434,10 @@ std::string LLDXHardware::getDriverVersionWMI(EGPUVendor vendor) { pEnumerator->Release(); } - if (SUCCEEDED(hrCoInitialize)) - { - CoUninitialize(); - } + + // supposed to always call CoUninitialize even if init returned false + CoUninitialize(); + return mDriverVersion; } @@ -687,7 +684,8 @@ BOOL LLDXHardware::getInfo(BOOL vram_only) BOOL ok = FALSE; HRESULT hr; - CoInitializeEx(NULL, COINIT_MULTITHREADED); + // CLSID_DxDiagProvider does not work with Multithreaded? + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); IDxDiagProvider *dx_diag_providerp = NULL; IDxDiagContainer *dx_diag_rootp = NULL; @@ -976,7 +974,7 @@ LLSD LLDXHardware::getDisplayInfo() LLTimer hw_timer; HRESULT hr; LLSD ret; - CoInitializeEx(NULL, COINIT_MULTITHREADED); + CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); IDxDiagProvider *dx_diag_providerp = NULL; IDxDiagContainer *dx_diag_rootp = NULL; -- cgit v1.2.3