fix(renderer): defend against WebGL context loss in atlas clearing

Rapid TUI redraws on panes with lost graphics contexts could cause SIGSEGV
crashes on Linux when clearTextureAtlas() attempted to access corrupted GPU
memory. The exception thrown by WebGL ops on lost contexts happens at the
GPU driver level (signal-based crash), not as a JavaScript exception.

Add defensive context-loss check before calling clearTextureAtlas() to prevent
accessing WebGL state on lost contexts. Mark the pane as having disabled WebGL
to prevent future atlas clear attempts on the same context.

Fixes Scan-16 Linux Terminal SIGSEGV crashes from rapid pane output operations.
This commit is contained in:
m4air
2026-09-20 07:16:09 -07:00
parent 4c73392227
commit 8a1506d055
@@ -183,13 +183,24 @@ export function clearWebglTextureAtlas(pane: ManagedPaneInternal): void {
if (pane.webglDisabledAfterContextLoss) {
return
}
if (!pane.webglAddon) {
return
}
// Defensive: detect lost context before attempting clear. Signal-level crashes
// (SIGSEGV) from WebGL ops on lost contexts can't be caught as exceptions; check
// context state first to avoid GPU driver crashes on rapid TUI redraws.
if (isPaneWebglContextLost(pane)) {
pane.webglDisabledAfterContextLoss = true
return
}
try {
// Why: rapid TUI redraws can corrupt xterm's WebGL glyph atlas without a
// context-loss event. Clearing the atlas preserves GPU rendering and forces
// a fresh paint when the pane becomes visible/focused again.
pane.webglAddon?.clearTextureAtlas()
pane.webglAddon.clearTextureAtlas()
} catch {
/* ignore — pane may have been disposed in the meantime */
pane.webglDisabledAfterContextLoss = true
}
}