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 <enga@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Rafael Cintron <rafael.cintron@microsoft.com>
This commit is contained in:
Rafael Cintron 2021-03-03 18:42:34 +00:00 committed by Commit Bot service account
parent 9b5f442c78
commit c36a9e8579
1 changed files with 5 additions and 0 deletions

View File

@ -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));