dawn/node: Fix crash when using device after destroy()

Do not assign null to the wgpu::Device, as this will result in a nullptr dereference if you attempt to use the device after destruction.
The wgpu device correctly handles the error state of being used after destroy().

Fixes crashes of CTS tests:
'webgpu:api,validation,state,device_lost,destroy,*'

Change-Id: Ibee1078436efadf25f53735fbaa47d5fc5f74898
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/97442
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-07-28 14:11:17 +00:00 committed by Dawn LUCI CQ
parent 8b30c7f124
commit 316fb47afe
2 changed files with 4 additions and 2 deletions

View File

@ -172,7 +172,7 @@ GPUDevice::~GPUDevice() {
// Without this, we'll get a 'Promise not resolved or rejected' fatal message as the
// lost_promise_ is left hanging. We'll also not clean up any GPU objects before terminating the
// process, which is not a good idea.
if (device_) {
if (!destroyed_) {
destroy(env_);
}
}
@ -204,7 +204,7 @@ void GPUDevice::destroy(Napi::Env env) {
env_, interop::GPUDeviceLostReason::kDestroyed, "device was destroyed"));
}
device_.Destroy();
device_ = nullptr;
destroyed_ = true;
}
interop::Interface<interop::GPUBuffer> GPUDevice::createBuffer(

View File

@ -111,6 +111,8 @@ class GPUDevice final : public interop::GPUDevice {
// This promise's JS object lives as long as the device because it is stored in .lost
// of the wrapper JS object.
interop::Promise<interop::Interface<interop::GPUDeviceLostInfo>> lost_promise_;
bool destroyed_ = false;
};
} // namespace wgpu::binding