Ensure webgl texture atlas is released on dispose

This commit is contained in:
Daniel Imms
2022-10-08 07:32:51 -07:00
parent f88c0e7480
commit fc8043a25a
3 changed files with 18 additions and 19 deletions
@@ -12,8 +12,9 @@ import { ICoreBrowserService } from 'browser/services/Services';
import { IRenderDimensions, ITextureAtlas } from 'browser/renderer/shared/Types';
import { CellData } from 'common/buffer/CellData';
import { throwIfFalsy } from 'browser/renderer/shared/RendererUtils';
import { Disposable, toDisposable } from 'common/Lifecycle';
export abstract class BaseRenderLayer implements IRenderLayer {
export abstract class BaseRenderLayer extends Disposable implements IRenderLayer {
private _canvas: HTMLCanvasElement;
protected _ctx!: CanvasRenderingContext2D;
private _scaledCharWidth: number = 0;
@@ -33,18 +34,16 @@ export abstract class BaseRenderLayer implements IRenderLayer {
protected _colors: IColorSet,
protected readonly _coreBrowserService: ICoreBrowserService
) {
super();
this._canvas = document.createElement('canvas');
this._canvas.classList.add(`xterm-${id}-layer`);
this._canvas.style.zIndex = zIndex.toString();
this._initCanvas();
this._container.appendChild(this._canvas);
}
public dispose(): void {
this._canvas.remove();
if (this._charAtlas) {
this._charAtlas.dispose();
}
this.register(toDisposable(() => {
this._canvas.remove();
this._charAtlas?.dispose();
}));
}
private _initCanvas(): void {
@@ -10,6 +10,7 @@ import { ITerminal, IColorSet, ILinkifierEvent } from 'browser/Types';
import { IRenderDimensions } from 'browser/renderer/shared/Types';
import { ICoreBrowserService } from 'browser/services/Services';
import { is256Color } from 'browser/renderer/shared/CharAtlasUtils';
import { toDisposable } from 'common/Lifecycle';
export class LinkRenderLayer extends BaseRenderLayer {
private _state: ILinkifierEvent | undefined;
@@ -23,8 +24,8 @@ export class LinkRenderLayer extends BaseRenderLayer {
) {
super(container, 'link', zIndex, true, colors, coreBrowserService);
terminal.linkifier2.onShowLinkUnderline(e => this._onShowLinkUnderline(e));
terminal.linkifier2.onHideLinkUnderline(e => this._onHideLinkUnderline(e));
this.register(terminal.linkifier2.onShowLinkUnderline(e => this._onShowLinkUnderline(e)));
this.register(terminal.linkifier2.onHideLinkUnderline(e => this._onHideLinkUnderline(e)));
}
public resize(terminal: Terminal, dim: IRenderDimensions): void {