Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Valigursky committed Oct 14, 2024
1 parent ad8f165 commit 46d2dd1
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/platform/graphics/webgpu/webgpu-graphics-device.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 46d2dd1

Please sign in to comment.