Skip to content

Commit dbd2e8d

Browse files
committed
fix small todispose bug
1 parent 5956c25 commit dbd2e8d

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

frontend/app/view/term/termwrap.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,10 @@ export class TermWrap {
8585
multiInputCallback: (data: string) => void;
8686
sendDataHandler: (data: string) => void;
8787
onSearchResultsDidChange?: (result: { resultIndex: number; resultCount: number }) => void;
88-
private toDispose: TermTypes.IDisposable[] = [];
88+
toDispose: TermTypes.IDisposable[] = [];
8989
webglAddon: WebglAddon | null = null;
9090
canvasAddon: CanvasAddon | null = null;
91+
webglContextLossDisposable: TermTypes.IDisposable | null = null;
9192
webglEnabledAtom: jotai.PrimitiveAtom<boolean>;
9293
pasteActive: boolean = false;
9394
lastUpdated: number;
@@ -307,13 +308,18 @@ export class TermWrap {
307308
}
308309
if (!WebGLSupported) {
309310
renderer = "canvas";
311+
if (this.canvasAddon != null) {
312+
return;
313+
}
310314
}
311315
} else {
312316
if (this.canvasAddon != null) {
313317
return;
314318
}
315319
}
316320
if (this.webglAddon != null) {
321+
this.webglContextLossDisposable?.dispose();
322+
this.webglContextLossDisposable = null;
317323
this.webglAddon.dispose();
318324
this.webglAddon = null;
319325
globalStore.set(this.webglEnabledAtom, false);
@@ -324,13 +330,9 @@ export class TermWrap {
324330
}
325331
if (renderer === "webgl") {
326332
const addon = new WebglAddon();
327-
this.toDispose.push(
328-
addon.onContextLoss(() => {
329-
if (addon === this.webglAddon) {
330-
this.setTermRenderer("canvas");
331-
}
332-
})
333-
);
333+
this.webglContextLossDisposable = addon.onContextLoss(() => {
334+
this.setTermRenderer("canvas");
335+
});
334336
this.terminal.loadAddon(addon);
335337
this.webglAddon = addon;
336338
globalStore.set(this.webglEnabledAtom, true);
@@ -468,6 +470,8 @@ export class TermWrap {
468470
} catch (_) {}
469471
});
470472
this.promptMarkers = [];
473+
this.webglContextLossDisposable?.dispose();
474+
this.webglContextLossDisposable = null;
471475
this.terminal.dispose();
472476
this.toDispose.forEach((d) => {
473477
try {

0 commit comments

Comments
 (0)