From e499f2e081316fa245f149b2b8eab405c6be47e5 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 29 Oct 2024 18:04:47 +0100 Subject: [PATCH] [d3d11] Fix potential crash when mapping a default image fails This also marginally shortens common code paths. --- src/d3d11/d3d11_context_imm.cpp | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/d3d11/d3d11_context_imm.cpp b/src/d3d11/d3d11_context_imm.cpp index 6dc8a832f0d..58b6b2c1cf2 100644 --- a/src/d3d11/d3d11_context_imm.cpp +++ b/src/d3d11/d3d11_context_imm.cpp @@ -280,23 +280,14 @@ namespace dxvk { D3D11_RESOURCE_DIMENSION resourceDim = D3D11_RESOURCE_DIMENSION_UNKNOWN; pResource->GetType(&resourceDim); - HRESULT hr; - if (likely(resourceDim == D3D11_RESOURCE_DIMENSION_BUFFER)) { - hr = MapBuffer( + return MapBuffer( static_cast(pResource), MapType, MapFlags, pMappedResource); } else { - hr = MapImage( - GetCommonTexture(pResource), - Subresource, MapType, MapFlags, - pMappedResource); + return MapImage(GetCommonTexture(pResource), + Subresource, MapType, MapFlags, pMappedResource); } - - if (unlikely(FAILED(hr))) - *pMappedResource = D3D11_MAPPED_SUBRESOURCE(); - - return hr; } @@ -328,6 +319,7 @@ namespace dxvk { if (unlikely(pResource->GetMapMode() == D3D11_COMMON_BUFFER_MAP_MODE_NONE)) { Logger::err("D3D11: Cannot map a device-local buffer"); + *pMappedResource = D3D11_MAPPED_SUBRESOURCE(); return E_INVALIDARG; } @@ -399,8 +391,10 @@ namespace dxvk { pMappedResource->DepthPitch = bufferSize; return S_OK; } else { - if (!WaitForResource(*buffer, sequenceNumber, MapType, MapFlags)) + if (!WaitForResource(*buffer, sequenceNumber, MapType, MapFlags)) { + *pMappedResource = D3D11_MAPPED_SUBRESOURCE(); return DXGI_ERROR_WAS_STILL_DRAWING; + } pMappedResource->pData = pResource->GetMapPtr(); pMappedResource->RowPitch = bufferSize; @@ -421,7 +415,10 @@ namespace dxvk { const Rc mappedBuffer = pResource->GetMappedBuffer(Subresource); auto mapMode = pResource->GetMapMode(); - + + if (pMappedResource) + *pMappedResource = D3D11_MAPPED_SUBRESOURCE(); + if (unlikely(mapMode == D3D11_COMMON_TEXTURE_MAP_MODE_NONE)) { Logger::err("D3D11: Cannot map a device-local image"); return E_INVALIDARG;