From 46d2dd18be930b2df5ac53126253ccbabedccd9a Mon Sep 17 00:00:00 2001 From: Martin Valigursky Date: Mon, 14 Oct 2024 15:54:23 +0100 Subject: [PATCH] update --- .../graphics/webgpu/webgpu-graphics-device.js | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/platform/graphics/webgpu/webgpu-graphics-device.js b/src/platform/graphics/webgpu/webgpu-graphics-device.js index a2cebee630b..fe8d11a2848 100644 --- a/src/platform/graphics/webgpu/webgpu-graphics-device.js +++ b/src/platform/graphics/webgpu/webgpu-graphics-device.js @@ -264,19 +264,8 @@ class WebgpuGraphicsDevice extends GraphicsDevice { */ this.wgpu = await this.gpuAdapter.requestDevice(deviceDescr); - this.wgpu.lost?.then(async (info) => { - - // reason is 'destroyed' if we intentionally destroy the device - if (info.reason !== 'destroyed') { - Debug.warn(`WebGPU device was lost: ${info.message}, this needs to be handled`); - - super.loseContext(); - - await this.createDevice(); - - super.restoreContext(); - } - }); + // handle lost device + this.wgpu.lost?.then(this.handleDeviceLost.bind(this)); this.initDeviceCaps(); @@ -354,6 +343,19 @@ class WebgpuGraphicsDevice extends GraphicsDevice { return this; } + async handleDeviceLost(info) { + // reason is 'destroyed' if we intentionally destroy the device + if (info.reason !== 'destroyed') { + Debug.warn(`WebGPU device was lost: ${info.message}, this needs to be handled`); + + super.loseContext(); // 'super' works correctly here + + await this.createDevice(); // Ensure this method is defined in your class + + super.restoreContext(); // 'super' works correctly here + } + } + postInit() { super.postInit();