From f309affff2d7482188a67cd3c56cabdcb69fe543 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Wed, 31 Aug 2022 05:44:48 -0700 Subject: [PATCH] Tweak handling of _contextRestorationTimeout --- addons/xterm-addon-webgl/src/WebglRenderer.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/addons/xterm-addon-webgl/src/WebglRenderer.ts b/addons/xterm-addon-webgl/src/WebglRenderer.ts index 23c763a2..6dcd3061 100644 --- a/addons/xterm-addon-webgl/src/WebglRenderer.ts +++ b/addons/xterm-addon-webgl/src/WebglRenderer.ts @@ -53,6 +53,7 @@ export class WebglRenderer extends Disposable implements IRenderer { private _core: ITerminal; private _isAttached: boolean; + private _contextRestorationTimeout: number | undefined; private _onChangeTextureAtlas = new EventEmitter(); public get onChangeTextureAtlas(): IEvent { return this._onChangeTextureAtlas.event; } @@ -62,8 +63,6 @@ export class WebglRenderer extends Disposable implements IRenderer { private _onContextLoss = new EventEmitter(); public get onContextLoss(): IEvent { return this._onContextLoss.event; } - private _contextRestorationTimeout: number | undefined; - constructor( private _terminal: Terminal, private _colors: IColorSet, @@ -117,16 +116,15 @@ export class WebglRenderer extends Disposable implements IRenderer { // Wait a few seconds to see if the 'webglcontextrestored' event is fired. // If not, dispatch the onContextLoss notification to observers. this._contextRestorationTimeout = setTimeout(() => { - if (this._contextRestorationTimeout !== 0) { - console.log('webgl context not restored; firing onContextLoss'); - this._onContextLoss.fire(e); - } + this._contextRestorationTimeout = undefined; + console.warn('webgl context not restored; firing onContextLoss'); + this._onContextLoss.fire(e); }, 3000 /* ms */); })); this.register(addDisposableDomListener(this._canvas, 'webglcontextrestored', (e) => { - console.log('webglcontextrestored event received'); + console.warn('webglcontextrestored event received'); clearTimeout(this._contextRestorationTimeout); - this._contextRestorationTimeout = 0; + this._contextRestorationTimeout = undefined; // The texture atlas and glyph renderer must be fully reinitialized // because their contents have been lost. removeTerminalFromCache(this._terminal);