From 6babc22ec0dc148da2ae7efdea7f243ff09fd82b Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 28 Mar 2018 11:56:58 +0200 Subject: [PATCH] [dxgi] Reset pointers before returning an error Also fixes a refcount issue and minor code formatting issues. --- src/dxgi/dxgi_adapter.cpp | 20 ++++++++++++-------- src/dxgi/dxgi_device.cpp | 3 +++ src/dxgi/dxgi_factory.cpp | 12 +++++++++--- src/dxgi/dxgi_output.cpp | 4 +--- src/dxgi/dxgi_swapchain.cpp | 1 + 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/dxgi/dxgi_adapter.cpp b/src/dxgi/dxgi_adapter.cpp index 42ffe6397..0bdbf836c 100644 --- a/src/dxgi/dxgi_adapter.cpp +++ b/src/dxgi/dxgi_adapter.cpp @@ -60,8 +60,10 @@ namespace dxvk { if (ppOutput == nullptr) return DXGI_ERROR_INVALID_CALL; - if (Output > 0) + if (Output > 0) { + *ppOutput = nullptr; return DXGI_ERROR_NOT_FOUND; + } // TODO support multiple monitors HMONITOR monitor = ::MonitorFromPoint({ 0, 0 }, MONITOR_DEFAULTTOPRIMARY); @@ -72,7 +74,7 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE DxgiAdapter::GetDesc(DXGI_ADAPTER_DESC* pDesc) { if (pDesc == nullptr) - return E_INVALIDARG; + return DXGI_ERROR_INVALID_CALL; DXGI_ADAPTER_DESC1 desc1; HRESULT hr = this->GetDesc1(&desc1); @@ -176,16 +178,18 @@ namespace dxvk { HRESULT DxgiAdapter::GetOutputFromMonitor( HMONITOR Monitor, IDXGIOutput** ppOutput) { - Com output; + if (ppOutput == nullptr) + return DXGI_ERROR_INVALID_CALL; - for (uint32_t i = 0; SUCCEEDED(EnumOutputs(i, &output)); i++) { + for (uint32_t i = 0; SUCCEEDED(EnumOutputs(i, ppOutput)); i++) { DXGI_OUTPUT_DESC outputDesc; - output->GetDesc(&outputDesc); + (*ppOutput)->GetDesc(&outputDesc); - if (outputDesc.Monitor == Monitor) { - *ppOutput = output.ref(); + if (outputDesc.Monitor == Monitor) return S_OK; - } + + (*ppOutput)->Release(); + (*ppOutput) = nullptr; } // No such output found diff --git a/src/dxgi/dxgi_device.cpp b/src/dxgi/dxgi_device.cpp index 876b2ac7b..61ca5b994 100644 --- a/src/dxgi/dxgi_device.cpp +++ b/src/dxgi/dxgi_device.cpp @@ -51,6 +51,9 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE DxgiDevice::GetAdapter( IDXGIAdapter** pAdapter) { + if (pAdapter == nullptr) + return DXGI_ERROR_INVALID_CALL; + *pAdapter = static_cast(m_adapter.ref()); return S_OK; } diff --git a/src/dxgi/dxgi_factory.cpp b/src/dxgi/dxgi_factory.cpp index 55cfdb3e7..37ca1f31a 100644 --- a/src/dxgi/dxgi_factory.cpp +++ b/src/dxgi/dxgi_factory.cpp @@ -41,6 +41,10 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE DxgiFactory::CreateSoftwareAdapter( HMODULE Module, IDXGIAdapter** ppAdapter) { + if (ppAdapter == nullptr) + return DXGI_ERROR_INVALID_CALL; + + *ppAdapter = nullptr; Logger::err("DxgiFactory::CreateSoftwareAdapter: Software adapters not supported"); return DXGI_ERROR_UNSUPPORTED; } @@ -52,6 +56,7 @@ namespace dxvk { IDXGISwapChain** ppSwapChain) { if (ppSwapChain == nullptr || pDesc == nullptr || pDevice == NULL) return DXGI_ERROR_INVALID_CALL; + if (pDesc->OutputWindow == nullptr) return DXGI_ERROR_INVALID_CALL; @@ -73,8 +78,7 @@ namespace dxvk { IDXGIAdapter1* handle = nullptr; HRESULT hr = this->EnumAdapters1(Adapter, &handle); - if (SUCCEEDED(hr)) - *ppAdapter = handle; + *ppAdapter = handle; return hr; } @@ -85,8 +89,10 @@ namespace dxvk { if (ppAdapter == nullptr) return DXGI_ERROR_INVALID_CALL; - if (Adapter >= m_adapters.size()) + if (Adapter >= m_adapters.size()) { + *ppAdapter = nullptr; return DXGI_ERROR_NOT_FOUND; + } *ppAdapter = ref(new DxgiAdapter( this, m_adapters.at(Adapter))); diff --git a/src/dxgi/dxgi_output.cpp b/src/dxgi/dxgi_output.cpp index 4d708c549..a140f33d7 100644 --- a/src/dxgi/dxgi_output.cpp +++ b/src/dxgi/dxgi_output.cpp @@ -36,9 +36,7 @@ namespace dxvk { } - HRESULT STDMETHODCALLTYPE DxgiOutput::GetParent( - REFIID riid, - void **ppParent) { + HRESULT STDMETHODCALLTYPE DxgiOutput::GetParent(REFIID riid, void **ppParent) { return m_adapter->QueryInterface(riid, ppParent); } diff --git a/src/dxgi/dxgi_swapchain.cpp b/src/dxgi/dxgi_swapchain.cpp index 6005c43c3..a02ef242f 100644 --- a/src/dxgi/dxgi_swapchain.cpp +++ b/src/dxgi/dxgi_swapchain.cpp @@ -141,6 +141,7 @@ namespace dxvk { if (ppTarget != nullptr) { *ppTarget = nullptr; + if (!m_desc.Windowed) hr = this->GetContainingOutput(ppTarget); }