diff --git a/src/d3d9/d3d9_common_texture.cpp b/src/d3d9/d3d9_common_texture.cpp index ba8a3140a94..be7474b56fc 100644 --- a/src/d3d9/d3d9_common_texture.cpp +++ b/src/d3d9/d3d9_common_texture.cpp @@ -194,6 +194,8 @@ namespace dxvk { m_data.Map(); uint8_t* ptr = reinterpret_cast(m_data.Ptr()); + if (ptr == nullptr) + return nullptr; ptr += m_memoryOffset[Subresource]; return ptr; } diff --git a/src/d3d9/d3d9_initializer.cpp b/src/d3d9/d3d9_initializer.cpp index 26dae412e55..ece83bd743e 100644 --- a/src/d3d9/d3d9_initializer.cpp +++ b/src/d3d9/d3d9_initializer.cpp @@ -44,11 +44,21 @@ namespace dxvk { if (pTexture->GetMapMode() == D3D9_COMMON_TEXTURE_MAP_MODE_NONE) return; + void* mapPtr = nullptr; + + if (pTexture->Desc()->Pool != D3DPOOL_DEFAULT) { + mapPtr = pTexture->GetData(0); + if (mapPtr == nullptr) + throw DxvkError("D3D9: InitTexture: map failed"); + } + if (pTexture->GetImage() != nullptr) InitDeviceLocalTexture(pTexture); - if (pTexture->Desc()->Pool != D3DPOOL_DEFAULT) - InitHostVisibleTexture(pTexture, pInitialData); + if (mapPtr != nullptr) { + InitHostVisibleTexture(pTexture, pInitialData, mapPtr); + pTexture->UnmapData(); + } } @@ -109,11 +119,11 @@ namespace dxvk { void D3D9Initializer::InitHostVisibleTexture( D3D9CommonTexture* pTexture, - void* pInitialData) { + void* pInitialData, + void* mapPtr) { // If the buffer is mapped, we can write data directly // to the mapped memory region instead of doing it on // the GPU. Same goes for zero-initialization. - void* mapPtr = pTexture->GetData(0); if (pInitialData) { // Initial data is only supported for textures with 1 subresource VkExtent3D mipExtent = pTexture->GetExtentMip(0); @@ -141,7 +151,6 @@ namespace dxvk { mapPtr, 0, pTexture->GetTotalSize()); } - pTexture->UnmapData(); } @@ -159,4 +168,4 @@ namespace dxvk { m_transferMemory = 0; } -} \ No newline at end of file +} diff --git a/src/d3d9/d3d9_initializer.h b/src/d3d9/d3d9_initializer.h index 59802f9550f..69ce5d33d2a 100644 --- a/src/d3d9/d3d9_initializer.h +++ b/src/d3d9/d3d9_initializer.h @@ -52,11 +52,12 @@ namespace dxvk { void InitHostVisibleTexture( D3D9CommonTexture* pTexture, - void* pInitialData); + void* pInitialData, + void* mapPtr); void FlushImplicit(); void FlushInternal(); }; -} \ No newline at end of file +}