From 35238ec4d11cbf280209fab82ec2f85879e4c128 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 19 Sep 2018 11:59:53 +0200 Subject: [PATCH] [d3d11] Make D3D11 context methods more robust to null pointers Assetto Corsa tries to do some questionable things when reflections are disabled in the game options. Refs #648. --- src/d3d11/d3d11_context.cpp | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/d3d11/d3d11_context.cpp b/src/d3d11/d3d11_context.cpp index 1965c12d..b0b2d8bf 100644 --- a/src/d3d11/d3d11_context.cpp +++ b/src/d3d11/d3d11_context.cpp @@ -63,10 +63,13 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11DeviceContext::DiscardResource(ID3D11Resource* pResource) { + if (!pResource) + return; + + // We don't support the Discard API for images D3D11_RESOURCE_DIMENSION resType = D3D11_RESOURCE_DIMENSION_UNKNOWN; pResource->GetType(&resType); - // We don't support the Discard API for images if (resType == D3D11_RESOURCE_DIMENSION_BUFFER) DiscardBuffer(static_cast(pResource)); } @@ -197,7 +200,7 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11DeviceContext::Begin(ID3D11Asynchronous *pAsync) { - if (pAsync == nullptr) + if (!pAsync) return; Com query; @@ -217,7 +220,7 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11DeviceContext::End(ID3D11Asynchronous *pAsync) { - if (pAsync == nullptr) + if (!pAsync) return; Com query; @@ -508,6 +511,9 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11DeviceContext::CopyResource( ID3D11Resource* pDstResource, ID3D11Resource* pSrcResource) { + if (!pDstResource || !pSrcResource) + return; + D3D11_RESOURCE_DIMENSION dstResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN; D3D11_RESOURCE_DIMENSION srcResourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN; @@ -606,6 +612,9 @@ namespace dxvk { auto buf = static_cast(pDstBuffer); auto uav = static_cast(pSrcView); + if (!buf || !uav) + return; + EmitCs([ cDstSlice = buf->GetBufferSlice(DstAlignedByteOffset), cSrcSlice = uav->GetCounterSlice() @@ -625,7 +634,7 @@ namespace dxvk { const FLOAT ColorRGBA[4]) { auto rtv = static_cast(pRenderTargetView); - if (rtv == nullptr) + if (!rtv) return; const Rc view = rtv->GetImageView(); @@ -653,7 +662,7 @@ namespace dxvk { const UINT Values[4]) { auto uav = static_cast(pUnorderedAccessView); - if (uav == nullptr) + if (!uav) return; // Gather UAV format info. We'll use this to determine @@ -746,7 +755,7 @@ namespace dxvk { const FLOAT Values[4]) { auto uav = static_cast(pUnorderedAccessView); - if (uav == nullptr) + if (!uav) return; VkClearValue clearValue; @@ -786,7 +795,7 @@ namespace dxvk { UINT8 Stencil) { auto dsv = static_cast(pDepthStencilView); - if (dsv == nullptr) + if (!dsv) return; // Figure out which aspects to clear based @@ -966,8 +975,8 @@ namespace dxvk { void STDMETHODCALLTYPE D3D11DeviceContext::GenerateMips(ID3D11ShaderResourceView* pShaderResourceView) { auto view = static_cast(pShaderResourceView); - - if (view->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) + + if (!view || view->GetResourceType() == D3D11_RESOURCE_DIMENSION_BUFFER) return; EmitCs([cDstImageView = view->GetImageView()] @@ -998,6 +1007,9 @@ namespace dxvk { UINT SrcRowPitch, UINT SrcDepthPitch, UINT CopyFlags) { + if (!pDstResource) + return; + // We need a different code path for buffers D3D11_RESOURCE_DIMENSION resourceType; pDstResource->GetType(&resourceType); @@ -1134,6 +1146,9 @@ namespace dxvk { ID3D11Resource* pSrcResource, UINT SrcSubresource, DXGI_FORMAT Format) { + if (!pDstResource || !pSrcResource) + return; + D3D11_RESOURCE_DIMENSION dstResourceType; D3D11_RESOURCE_DIMENSION srcResourceType;