diff --git a/DirectX10/d3d10Wrapper.cpp b/DirectX10/d3d10Wrapper.cpp index 0837d63d1..5e09724bd 100644 --- a/DirectX10/d3d10Wrapper.cpp +++ b/DirectX10/d3d10Wrapper.cpp @@ -422,10 +422,11 @@ HRESULT WINAPI D3D10CreateDeviceAndSwapChain(D3D11Base::IDXGIAdapter *pAdapter, D3D11Base::ID3D10Device *origDevice = 0; HRESULT ret = (*_D3D10CreateDeviceAndSwapChain)(ReplaceAdapter(pAdapter), DriverType, Software, Flags, SDKVersion, pSwapChainDesc, ppSwapChain, &origDevice); - if (ret != S_OK) + + // Changed to recognize that >0 DXGISTATUS values are possible, not just S_OK. + if (FAILED(ret)) { if (LogFile) fprintf(LogFile, " failed with HRESULT=%x\n", ret); - return ret; } diff --git a/DirectX11/d3d11Wrapper.cpp b/DirectX11/d3d11Wrapper.cpp index f589e25d8..4fc12c4dc 100644 --- a/DirectX11/d3d11Wrapper.cpp +++ b/DirectX11/d3d11Wrapper.cpp @@ -2186,10 +2186,11 @@ HRESULT WINAPI D3D11CreateDeviceAndSwapChain( D3D11Base::ID3D11DeviceContext *origContext = 0; HRESULT ret = (*_D3D11CreateDeviceAndSwapChain)(ReplaceAdapter(pAdapter), DriverType, Software, Flags, pFeatureLevels, FeatureLevels, SDKVersion, pSwapChainDesc, ppSwapChain, &origDevice, pFeatureLevel, &origContext); - if (ret != S_OK) + + // Changed to recognize that >0 DXGISTATUS values are possible, not just S_OK. + if (FAILED(ret)) { if (LogFile) fprintf(LogFile, " failed with HRESULT=%x\n", ret); - return ret; } @@ -2214,7 +2215,7 @@ HRESULT WINAPI D3D11CreateDeviceAndSwapChain( *ppDevice = wrapper; D3D11Wrapper::ID3D11DeviceContext *wrapper2 = D3D11Wrapper::ID3D11DeviceContext::GetDirect3DDeviceContext(origContext); - if(wrapper == NULL) + if (wrapper2 == NULL) { if (LogFile) fprintf(LogFile, " error allocating wrapper2.\n"); diff --git a/DirectXGI/Direct3DXGIFunctions.h b/DirectXGI/Direct3DXGIFunctions.h index e8b49bd21..f29949e50 100644 --- a/DirectXGI/Direct3DXGIFunctions.h +++ b/DirectXGI/Direct3DXGIFunctions.h @@ -171,9 +171,10 @@ STDMETHODIMP D3D11Wrapper::IDXGIFactory::CreateSwapChain(THIS_ // can be occluded when we return from creating the real swap chain. // The check below was looking ONLY for S_OK, and that would lead to it skipping the sub-block // which set up ppSwapChain and returned it. So, ppSwapChain==NULL and it would crash, sometimes. - // There are other legitimate DXGI_STATUS results, so checking for FAILED is the correct way. + // There are other legitimate DXGI_STATUS results, so checking for SUCCEEDED is the correct way. + // Same bug fix is applied for the other CreateSwapChain* variants. - if (!FAILED(hr)) + if (SUCCEEDED(hr)) { *ppSwapChain = D3D11Wrapper::IDXGISwapChain::GetDirectSwapChain(origSwapChain); if ((*ppSwapChain)->m_WrappedDevice) (*ppSwapChain)->m_WrappedDevice->Release(); @@ -223,7 +224,9 @@ STDMETHODIMP D3D11Wrapper::IDXGIFactory2::CreateSwapChainForHwnd(THIS_ HRESULT hr = -1; if (pRestrictToOutput) hr = GetFactory2()->CreateSwapChainForHwnd(realDevice, hWnd, pDesc, pFullscreenDesc, pRestrictToOutput->m_pOutput, &origSwapChain); - if (hr == S_OK) + if (LogFile) fprintf(LogFile, " return value = %x\n", hr); + + if (SUCCEEDED(hr)) { *ppSwapChain = D3D11Wrapper::IDXGISwapChain1::GetDirectSwapChain(origSwapChain); if ((*ppSwapChain)->m_WrappedDevice) (*ppSwapChain)->m_WrappedDevice->Release(); @@ -231,8 +234,6 @@ STDMETHODIMP D3D11Wrapper::IDXGIFactory2::CreateSwapChainForHwnd(THIS_ (*ppSwapChain)->m_RealDevice = realDevice; if (pDesc) SendScreenResolution(pDevice, pDesc->Width, pDesc->Height); } - - if (LogFile) fprintf(LogFile, " return value = %x\n", hr); return hr; } @@ -263,7 +264,9 @@ STDMETHODIMP D3D11Wrapper::IDXGIFactory2::CreateSwapChainForCoreWindow(THIS_ HRESULT hr = -1; if (pRestrictToOutput) hr = GetFactory2()->CreateSwapChainForCoreWindow(realDevice, pWindow, pDesc, pRestrictToOutput->m_pOutput, &origSwapChain); - if (hr == S_OK) + if (LogFile) fprintf(LogFile, " return value = %x\n", hr); + + if (SUCCEEDED(hr)) { *ppSwapChain = D3D11Wrapper::IDXGISwapChain1::GetDirectSwapChain(origSwapChain); if ((*ppSwapChain)->m_WrappedDevice) (*ppSwapChain)->m_WrappedDevice->Release(); @@ -272,8 +275,6 @@ STDMETHODIMP D3D11Wrapper::IDXGIFactory2::CreateSwapChainForCoreWindow(THIS_ if (pDesc) SendScreenResolution(pDevice, pDesc->Width, pDesc->Height); } - if (LogFile) fprintf(LogFile, " return value = %x\n", hr); - return hr; } @@ -301,7 +302,9 @@ STDMETHODIMP D3D11Wrapper::IDXGIFactory2::CreateSwapChainForComposition(THIS_ HRESULT hr = -1; if (pRestrictToOutput) hr = GetFactory2()->CreateSwapChainForComposition(realDevice, pDesc, pRestrictToOutput->m_pOutput, &origSwapChain); - if (hr == S_OK) + if (LogFile) fprintf(LogFile, " return value = %x\n", hr); + + if (SUCCEEDED(hr)) { *ppSwapChain = D3D11Wrapper::IDXGISwapChain1::GetDirectSwapChain(origSwapChain); if ((*ppSwapChain)->m_WrappedDevice) (*ppSwapChain)->m_WrappedDevice->Release(); @@ -310,8 +313,6 @@ STDMETHODIMP D3D11Wrapper::IDXGIFactory2::CreateSwapChainForComposition(THIS_ if (pDesc) SendScreenResolution(pDevice, pDesc->Width, pDesc->Height); } - if (LogFile) fprintf(LogFile, " return value = %x\n", hr); - return hr; }