diff --git a/src/dawn/native/Buffer.cpp b/src/dawn/native/Buffer.cpp index 87db6ac7c0..fd13a3c82f 100644 --- a/src/dawn/native/Buffer.cpp +++ b/src/dawn/native/Buffer.cpp @@ -422,6 +422,9 @@ void BufferBase::APIUnmap() { } void BufferBase::Unmap() { + if (mState == BufferState::Destroyed) { + return; + } UnmapInternal(WGPUBufferMapAsyncStatus_UnmappedBeforeCallback); } diff --git a/src/dawn/tests/unittests/validation/BufferValidationTests.cpp b/src/dawn/tests/unittests/validation/BufferValidationTests.cpp index c943c4e820..3b2f3ae5e5 100644 --- a/src/dawn/tests/unittests/validation/BufferValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/BufferValidationTests.cpp @@ -528,6 +528,22 @@ TEST_F(BufferValidationTest, UnmapDestroyedBuffer) { } } +// Test that unmap then mapping a destroyed buffer is an error. +// Regression test for crbug.com/1388920. +TEST_F(BufferValidationTest, MapDestroyedBufferAfterUnmap) { + wgpu::Buffer buffer = CreateMapReadBuffer(4); + buffer.Destroy(); + buffer.Unmap(); + + ASSERT_DEVICE_ERROR(buffer.MapAsync( + wgpu::MapMode::Read, 0, wgpu::kWholeMapSize, + [](WGPUBufferMapAsyncStatus status, void* userdata) { + EXPECT_EQ(WGPUBufferMapAsyncStatus_Error, status); + }, + nullptr)); + WaitForAllOperations(device); +} + // Test that it is valid to submit a buffer in a queue with a map usage if it is unmapped TEST_F(BufferValidationTest, SubmitBufferWithMapUsage) { wgpu::BufferDescriptor descriptorA;