Skip to content

Commit a7a941c

Browse files
authored
Merge pull request #5305 from Tyriar/tyriar/ctx_slow
Fix issue where listeners remain after WebglRenderer throws
2 parents d81b25c + 1c98c52 commit a7a941c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

.github/workflows/ci.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
./addons/addon-webgl/out/* \
6767
./addons/addon-webgl/out-*st/*
6868
- name: Upload artifacts
69-
uses: actions/upload-artifact@v3
69+
uses: actions/upload-artifact@v4
7070
with:
7171
name: build-artifacts
7272
path: compressed-build.zip
@@ -108,7 +108,7 @@ jobs:
108108
run: |
109109
yarn --frozen-lockfile
110110
yarn install-addons
111-
- uses: actions/download-artifact@v3
111+
- uses: actions/download-artifact@v4
112112
with:
113113
name: build-artifacts
114114
- name: Unzip artifacts
@@ -150,7 +150,7 @@ jobs:
150150
with:
151151
token: ${{ secrets.GITHUB_TOKEN }}
152152
job: build
153-
- uses: actions/download-artifact@v3
153+
- uses: actions/download-artifact@v4
154154
with:
155155
name: build-artifacts
156156
- name: Unzip artifacts
@@ -191,7 +191,7 @@ jobs:
191191
with:
192192
token: ${{ secrets.GITHUB_TOKEN }}
193193
job: build
194-
- uses: actions/download-artifact@v3
194+
- uses: actions/download-artifact@v4
195195
with:
196196
name: build-artifacts
197197
- name: Unzip artifacts
@@ -249,7 +249,7 @@ jobs:
249249
yarn install-addons
250250
- name: Install playwright
251251
run: npx playwright install
252-
- uses: actions/download-artifact@v3
252+
- uses: actions/download-artifact@v4
253253
with:
254254
name: build-artifacts
255255
- name: Unzip artifacts

addons/addon-webgl/src/WebglRenderer.ts

+14-12
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,20 @@ export class WebglRenderer extends Disposable implements IRenderer {
7676
) {
7777
super();
7878

79+
// IMPORTANT: Canvas initialization and fetching of the context must be first in order to
80+
// prevent possible listeners leaking and continuing to operate after the WebglRenderer has been
81+
// discarded.
82+
this._canvas = this._coreBrowserService.mainDocument.createElement('canvas');
83+
const contextAttributes = {
84+
antialias: false,
85+
depth: false,
86+
preserveDrawingBuffer
87+
};
88+
this._gl = this._canvas.getContext('webgl2', contextAttributes) as IWebGL2RenderingContext;
89+
if (!this._gl) {
90+
throw new Error('WebGL2 not supported ' + this._gl);
91+
}
92+
7993
this._register(this._themeService.onChangeColors(() => this._handleColorChange()));
8094

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

94-
this._canvas = this._coreBrowserService.mainDocument.createElement('canvas');
95-
96-
const contextAttributes = {
97-
antialias: false,
98-
depth: false,
99-
preserveDrawingBuffer
100-
};
101-
this._gl = this._canvas.getContext('webgl2', contextAttributes) as IWebGL2RenderingContext;
102-
if (!this._gl) {
103-
throw new Error('WebGL2 not supported ' + this._gl);
104-
}
105-
106108
this._deviceMaxTextureSize = this._gl.getParameter(this._gl.MAX_TEXTURE_SIZE);
107109

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

0 commit comments

Comments
 (0)