From 8a1506d055677d3f0144b6e08abfa973d4196d2c Mon Sep 17 00:00:00 2001 From: m4air Date: Sun, 20 Sep 2026 07:16:09 -0700 Subject: [PATCH] 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. --- .../src/lib/pane-manager/pane-webgl-renderer.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts b/src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts index 23cf486cb6d..748219dd93f 100644 --- a/src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts +++ b/src/renderer/src/lib/pane-manager/pane-webgl-renderer.ts @@ -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 } }