Skip to content

Commit

Permalink
Merge pull request #5305 from Tyriar/tyriar/ctx_slow
Browse files Browse the repository at this point in the history
Fix issue where listeners remain after WebglRenderer throws
  • Loading branch information
Tyriar authored Feb 7, 2025
2 parents d81b25c + 1c98c52 commit a7a941c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
./addons/addon-webgl/out/* \
./addons/addon-webgl/out-*st/*
- name: Upload artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: compressed-build.zip
Expand Down Expand Up @@ -108,7 +108,7 @@ jobs:
run: |
yarn --frozen-lockfile
yarn install-addons
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: build-artifacts
- name: Unzip artifacts
Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
job: build
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: build-artifacts
- name: Unzip artifacts
Expand Down Expand Up @@ -191,7 +191,7 @@ jobs:
with:
token: ${{ secrets.GITHUB_TOKEN }}
job: build
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: build-artifacts
- name: Unzip artifacts
Expand Down Expand Up @@ -249,7 +249,7 @@ jobs:
yarn install-addons
- name: Install playwright
run: npx playwright install
- uses: actions/download-artifact@v3
- uses: actions/download-artifact@v4
with:
name: build-artifacts
- name: Unzip artifacts
Expand Down
26 changes: 14 additions & 12 deletions addons/addon-webgl/src/WebglRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ export class WebglRenderer extends Disposable implements IRenderer {
) {
super();

// IMPORTANT: Canvas initialization and fetching of the context must be first in order to
// prevent possible listeners leaking and continuing to operate after the WebglRenderer has been
// discarded.
this._canvas = this._coreBrowserService.mainDocument.createElement('canvas');
const contextAttributes = {
antialias: false,
depth: false,
preserveDrawingBuffer
};
this._gl = this._canvas.getContext('webgl2', contextAttributes) as IWebGL2RenderingContext;
if (!this._gl) {
throw new Error('WebGL2 not supported ' + this._gl);
}

this._register(this._themeService.onChangeColors(() => this._handleColorChange()));

this._cellColorResolver = new CellColorResolver(this._terminal, this._optionsService, this._model.selection, this._decorationService, this._coreBrowserService, this._themeService);
Expand All @@ -91,18 +105,6 @@ export class WebglRenderer extends Disposable implements IRenderer {
this._updateCursorBlink();
this._register(_optionsService.onOptionChange(() => this._handleOptionsChanged()));

this._canvas = this._coreBrowserService.mainDocument.createElement('canvas');

const contextAttributes = {
antialias: false,
depth: false,
preserveDrawingBuffer
};
this._gl = this._canvas.getContext('webgl2', contextAttributes) as IWebGL2RenderingContext;
if (!this._gl) {
throw new Error('WebGL2 not supported ' + this._gl);
}

this._deviceMaxTextureSize = this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE);

this._register(addDisposableListener(this._canvas, 'webglcontextlost', (e) => {
Expand Down

0 comments on commit a7a941c

Please sign in to comment.