diff --git a/src/dawn/node/binding/GPUDevice.cpp b/src/dawn/node/binding/GPUDevice.cpp index 8f0901153d..9ac8c2808a 100644 --- a/src/dawn/node/binding/GPUDevice.cpp +++ b/src/dawn/node/binding/GPUDevice.cpp @@ -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 GPUDevice::createBuffer( diff --git a/src/dawn/node/binding/GPUDevice.h b/src/dawn/node/binding/GPUDevice.h index 02a2ea80b1..9c53e9a444 100644 --- a/src/dawn/node/binding/GPUDevice.h +++ b/src/dawn/node/binding/GPUDevice.h @@ -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> lost_promise_; + + bool destroyed_ = false; }; } // namespace wgpu::binding