mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-09-14 15:13:51 +00:00
dawn/node: Avoid exception on teardown
If node is shutdown without first explicitly destroying the GPUDevice, the device's destructor will be called, which would automatically destroy the dawn device. Before doing this, it would first reject the lost-device promise. With newer versions of node, attempting to construct new GC'd objects on NodeJS tear-down triggers a fatal error. Work around this by adding a new state to promises, that allows promises to be destroyed without first being rejected or resolved, and without raising a 'Promise not resolved or rejected' fatal message. Change-Id: I810d6894d384511cdb7989b9c6c5b707dd68d8c2 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/116864 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Auto-Submit: Ben Clayton <bclayton@google.com> Kokoro: Ben Clayton <bclayton@google.com> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
3c760b850c
commit
e704336001
@ -174,7 +174,9 @@ GPUDevice::~GPUDevice() {
|
||||
// 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 (!destroyed_) {
|
||||
destroy(env_);
|
||||
lost_promise_.Discard();
|
||||
device_.Destroy();
|
||||
destroyed_ = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -185,6 +185,7 @@ enum class PromiseState {
|
||||
Pending,
|
||||
Resolved,
|
||||
Rejected,
|
||||
Discarded,
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
@ -206,6 +207,12 @@ class PromiseBase {
|
||||
|
||||
PromiseState GetState() const { return state_->state; }
|
||||
|
||||
// Place the promise into the Discarded state.
|
||||
// This state will not throw a fatal error if this promise has not been rejected or resolved by
|
||||
// the time it is finalized. This is useful for Node tear-down where the attempting to create
|
||||
// new objects will result in a fatal error.
|
||||
void Discard() { state_->state = PromiseState::Discarded; }
|
||||
|
||||
protected:
|
||||
void Resolve(Napi::Value value) const {
|
||||
state_->deferred.Resolve(value);
|
||||
|
Loading…
x
Reference in New Issue
Block a user