Skip to content

Commit

Permalink
[d3d11] Fix potential crash when mapping a default image fails
Browse files Browse the repository at this point in the history
This also marginally shortens common code paths.
  • Loading branch information
doitsujin committed Oct 29, 2024
1 parent c2928ab commit e499f2e
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/d3d11/d3d11_context_imm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<D3D11Buffer*>(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;
}


Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -421,7 +415,10 @@ namespace dxvk {
const Rc<DxvkBuffer> 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;
Expand Down

0 comments on commit e499f2e

Please sign in to comment.