diff --git a/web/src/webgpu.ts b/web/src/webgpu.ts index 199fa14235ee..5a25833d1a8f 100644 --- a/web/src/webgpu.ts +++ b/web/src/webgpu.ts @@ -169,9 +169,20 @@ function tryCreateBuffer(device: GPUDevice, descriptor: GPUBufferDescriptor) { const buffer = device.createBuffer(descriptor); - device.popErrorScope().then((error) => {if (error) {device.destroy(); console.error(error);}}); - device.popErrorScope().then((error) => {if (error) {device.destroy(); console.error(error);}}); - device.popErrorScope().then((error) => {if (error) {device.destroy(); console.error(error);}}); + // Destroy at most once even if multiple error types fire. + Promise.all([ + device.popErrorScope(), + device.popErrorScope(), + device.popErrorScope(), + ]).then((errors) => { + const captured = errors.filter((error): error is GPUError => error !== null); + if (captured.length > 0) { + device.destroy(); + captured.forEach((error) => console.error(error)); + } + }).catch((err) => { + console.error("Failed to pop error scopes:", err); + }); return buffer; }