From c36a9e8579a17d1afb730a3de6af12fb0a3c210d Mon Sep 17 00:00:00 2001 From: Rafael Cintron Date: Wed, 3 Mar 2021 18:42:34 +0000 Subject: [PATCH] Protect Texture::DestroyImpl against multiple calls for D3D12 Calling Texture::DestroyImpl will cause a crash when passing a nullptr D3D12 resource to the Present method of ID3D12SharingContract. Protect against crashes by checking whether the allocation we're destroying is valid before proceeding. Change-Id: Ifb68c1f85383db5027006cf435f43c84d1a463d9 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/42580 Reviewed-by: Austin Eng Reviewed-by: Corentin Wallez Commit-Queue: Rafael Cintron --- src/dawn_native/d3d12/TextureD3D12.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/dawn_native/d3d12/TextureD3D12.cpp b/src/dawn_native/d3d12/TextureD3D12.cpp index 7a45d076d4..6b90c0a475 100644 --- a/src/dawn_native/d3d12/TextureD3D12.cpp +++ b/src/dawn_native/d3d12/TextureD3D12.cpp @@ -567,6 +567,11 @@ namespace dawn_native { namespace d3d12 { device->DeallocateMemory(mResourceAllocation); + // Now that we've deallocated the memory, the texture is no longer a swap chain texture. + // We can set mSwapChainTexture to false to avoid passing a nullptr to + // ID3D12SharingContract::Present. + mSwapChainTexture = false; + if (mDxgiKeyedMutex != nullptr) { mDxgiKeyedMutex->ReleaseSync(uint64_t(mAcquireMutexKey) + 1); device->ReleaseKeyedMutexForTexture(std::move(mDxgiKeyedMutex));