fix: get gl lost state immediately

This commit is contained in:
zhuxudong
2025-07-21 18:13:17 +08:00
parent 9a6d81dc71
commit 32ffb7012c
2 changed files with 5 additions and 4 deletions

View File

@@ -131,7 +131,6 @@ export class Engine extends EventDispatcher {
private _destroyed: boolean = false;
private _frameInProcess: boolean = false;
private _waitingDestroy: boolean = false;
private _isDeviceLost: boolean = false;
private _waitingGC: boolean = false;
private _postProcessPasses = new Array<PostProcessPass>();
private _activePostProcessPasses = new Array<PostProcessPass>();
@@ -381,7 +380,7 @@ export class Engine extends EventDispatcher {
}
// Render scene and fire `onBeginRender` and `onEndRender`
if (!this._isDeviceLost) {
if (!this._hardwareRenderer.isContextLost) {
this._render(scenes);
}
@@ -652,7 +651,6 @@ export class Engine extends EventDispatcher {
}
private _onDeviceLost(): void {
this._isDeviceLost = true;
// Lose graphic resources
this.resourceManager._lostGraphicResources();
console.log("Device lost.");
@@ -677,7 +675,6 @@ export class Engine extends EventDispatcher {
.then(() => {
console.log("Graphic resource content restored.\n\n" + "Device restored.");
this.dispatch("devicerestored", this);
this._isDeviceLost = false;
})
.catch((error) => {
console.error(error);

View File

@@ -135,6 +135,10 @@ export class WebGLGraphicDevice implements IHardwareRenderer {
return this._gl;
}
get isContextLost() {
return this.gl.isContextLost();
}
get renderStates(): GLRenderStates {
return this._renderStates;
}