TextureAtlas._createNewPage only merged exactly-4 same-size page sets; with a heterogeneous size mix (e.g. 1024+512+512+512) it pushed past maxAtlasPages instead. GlyphRenderer's GL texture array and fragment-shader sampler array are sized to exactly maxAtlasPages, so the next render threw TypeError: Cannot read properties of undefined (reading 'version') and rendering froze (single-terminal breakage under long heavy-CLI sessions, vscode#322756). - Generalize merge selection to the largest same-size group of 2-4 pages (preferring 4, then larger sizes); AtlasPage already supported non-quad merges. Net page count never exceeds the cap. - Derive merging page indexes via _pages.indexOf instead of glyphs[0] .texturePage, which is empty-page safe. - Last resort when no same-size pair exists below max texture size (only possible when almost all pages are at max size): evict all pages; glyphs re-rasterize on demand and models rebuild via pagesVersion. - Defensive clamp in GlyphRenderer.render so any future overflow renders untextured glyphs and logs a warning instead of throwing mid-frame. WebglAtlasOverflow now passes (was 4x TypeError); full webgl suite 75/75.
@xterm/addon-webgl
An addon for xterm.js that enables a WebGL2-based renderer. This addon requires xterm.js v4+.
Install
npm install --save @xterm/addon-webgl
Usage
import { Terminal } from '@xterm/xterm';
import { WebglAddon } from '@xterm/addon-webgl';
const terminal = new Terminal();
terminal.open(element);
terminal.loadAddon(new WebglAddon());
See the full API for more advanced usage.
Handling Context Loss
The browser may drop WebGL contexts for various reasons like OOM or after the system has been suspended. There is an API exposed that fires the webglcontextlost event on the canvas so embedders can handle it however they wish. An easy, but suboptimal way, to handle this is by disposing of WebglAddon when the event fires:
const terminal = new Terminal();
const addon = new WebglAddon();
addon.onContextLoss(e => {
addon.dispose();
});
terminal.loadAddon(addon);
Read more about handling WebGL context losses on the Khronos wiki.