From 835d92b802aec5fedc9221a4fd51547df855d919 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 2 Dec 2018 15:52:17 +0100 Subject: [PATCH] [d3d10] D3D10CreateDeviceAndSwapChain: Ignore swap chain if null Like e4b91057ac74266671d806e535b76f0db6f409bc, this might fix some issues with ReShade in D3D10 games. --- src/d3d10/d3d10_main.cpp | 50 +++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/src/d3d10/d3d10_main.cpp b/src/d3d10/d3d10_main.cpp index c8ffe5888..e6ca3e870 100644 --- a/src/d3d10/d3d10_main.cpp +++ b/src/d3d10/d3d10_main.cpp @@ -152,6 +152,9 @@ extern "C" { InitReturnPtr(ppDevice); InitReturnPtr(ppSwapChain); + if (ppSwapChain && !pSwapChainDesc) + return E_INVALIDARG; + // Try to create the device as usual Com d3d10Device = nullptr; HRESULT hr = D3D10CreateDevice1(pAdapter, @@ -162,31 +165,30 @@ extern "C" { return hr; // Create the swap chain if requested - if (pSwapChainDesc == nullptr) - return E_INVALIDARG; - - Com dxgiDevice = nullptr; - Com dxgiAdapter = nullptr; - Com dxgiFactory = nullptr; + if (ppSwapChain) { + Com dxgiDevice = nullptr; + Com dxgiAdapter = nullptr; + Com dxgiFactory = nullptr; - if (FAILED(d3d10Device->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast(&dxgiDevice)))) { - Logger::err("D3D11CreateDeviceAndSwapChain: Failed to query DXGI device"); - return E_FAIL; - } - - if (FAILED(dxgiDevice->GetParent(__uuidof(IDXGIAdapter), reinterpret_cast(&dxgiAdapter)))) { - Logger::err("D3D11CreateDeviceAndSwapChain: Failed to query DXGI adapter"); - return E_FAIL; - } - - if (FAILED(dxgiAdapter->GetParent(__uuidof(IDXGIFactory), reinterpret_cast(&dxgiFactory)))) { - Logger::err("D3D11CreateDeviceAndSwapChain: Failed to query DXGI factory"); - return E_FAIL; - } - - if (FAILED(dxgiFactory->CreateSwapChain(d3d10Device.ptr(), pSwapChainDesc, ppSwapChain))) { - Logger::err("D3D11CreateDeviceAndSwapChain: Failed to create swap chain"); - return E_FAIL; + if (FAILED(d3d10Device->QueryInterface(__uuidof(IDXGIDevice), reinterpret_cast(&dxgiDevice)))) { + Logger::err("D3D11CreateDeviceAndSwapChain: Failed to query DXGI device"); + return E_FAIL; + } + + if (FAILED(dxgiDevice->GetParent(__uuidof(IDXGIAdapter), reinterpret_cast(&dxgiAdapter)))) { + Logger::err("D3D11CreateDeviceAndSwapChain: Failed to query DXGI adapter"); + return E_FAIL; + } + + if (FAILED(dxgiAdapter->GetParent(__uuidof(IDXGIFactory), reinterpret_cast(&dxgiFactory)))) { + Logger::err("D3D11CreateDeviceAndSwapChain: Failed to query DXGI factory"); + return E_FAIL; + } + + if (FAILED(dxgiFactory->CreateSwapChain(d3d10Device.ptr(), pSwapChainDesc, ppSwapChain))) { + Logger::err("D3D11CreateDeviceAndSwapChain: Failed to create swap chain"); + return E_FAIL; + } } // Write back device pointer