From 0320b4961ba17861ae5a950b6b9cbfd3f70714cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 15 May 2019 22:55:24 +0200 Subject: [PATCH 1/2] Add a missing error check to the D3D11 device creation. May help #12039? --- Windows/GPU/D3D11Context.cpp | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/Windows/GPU/D3D11Context.cpp b/Windows/GPU/D3D11Context.cpp index 4a88910136..c61cf399a2 100644 --- a/Windows/GPU/D3D11Context.cpp +++ b/Windows/GPU/D3D11Context.cpp @@ -103,33 +103,37 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { HRESULT hr = E_FAIL; std::vector adapterNames; std::string chosenAdapterName; + IDXGIFactory* pFactory = nullptr; if (result == LoadD3D11Error::SUCCESS) { std::vector adapters; int chosenAdapter = 0; - IDXGIFactory * pFactory = nullptr; - ptr_CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&pFactory); + hr = ptr_CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&pFactory); + if (SUCCEEDED(hr)) { - IDXGIAdapter *pAdapter; - for (UINT i = 0; pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; i++) { - adapters.push_back(pAdapter); - DXGI_ADAPTER_DESC desc; - pAdapter->GetDesc(&desc); - std::string str = ConvertWStringToUTF8(desc.Description); - adapterNames.push_back(str); - if (str == g_Config.sD3D11Device) { - chosenAdapter = i; + IDXGIAdapter* pAdapter; + for (UINT i = 0; pFactory->EnumAdapters(i, &pAdapter) != DXGI_ERROR_NOT_FOUND; i++) { + adapters.push_back(pAdapter); + DXGI_ADAPTER_DESC desc; + pAdapter->GetDesc(&desc); + std::string str = ConvertWStringToUTF8(desc.Description); + adapterNames.push_back(str); + if (str == g_Config.sD3D11Device) { + chosenAdapter = i; + } } - } - chosenAdapterName = adapterNames[chosenAdapter]; - hr = CreateTheDevice(adapters[chosenAdapter]); - for (int i = 0; i < (int)adapters.size(); i++) { - adapters[i]->Release(); + chosenAdapterName = adapterNames[chosenAdapter]; + hr = CreateTheDevice(adapters[chosenAdapter]); + for (int i = 0; i < (int)adapters.size(); i++) { + adapters[i]->Release(); + } } } if (FAILED(hr)) { + if (pFactory) + pFactory->Release(); const char *defaultError = "Your GPU does not appear to support Direct3D 11.\n\nWould you like to try again using Direct3D 9 instead?"; I18NCategory *err = GetI18NCategory("Error"); From 6117e37a14bb166552ef6173afbb6a7254f0a71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 15 May 2019 22:58:45 +0200 Subject: [PATCH 2/2] D3D11: Also properly check for the no-adapters case. --- Windows/GPU/D3D11Context.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Windows/GPU/D3D11Context.cpp b/Windows/GPU/D3D11Context.cpp index c61cf399a2..9537b3ad71 100644 --- a/Windows/GPU/D3D11Context.cpp +++ b/Windows/GPU/D3D11Context.cpp @@ -123,10 +123,15 @@ bool D3D11Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) { } } - chosenAdapterName = adapterNames[chosenAdapter]; - hr = CreateTheDevice(adapters[chosenAdapter]); - for (int i = 0; i < (int)adapters.size(); i++) { - adapters[i]->Release(); + if (!adapters.empty()) { + chosenAdapterName = adapterNames[chosenAdapter]; + hr = CreateTheDevice(adapters[chosenAdapter]); + for (int i = 0; i < (int)adapters.size(); i++) { + adapters[i]->Release(); + } + } else { + // No adapters found. Trip the error path below. + hr = E_FAIL; } } }