GlyphRenderer sizes its GL texture array and fragment-shader sampler array to exactly TextureAtlas.maxAtlasPages at construction, but _createNewPage pushes past that cap whenever a 4-page same-size merge is impossible (heterogeneous sizes, e.g. 1024+512+512+512). The next render throws TypeError: Cannot read properties of undefined (reading 'version') and rendering freezes — the single-terminal breakage vector for long heavy-CLI sessions (vscode#322756). The test builds the renderer with maxAtlasPages=4 (same code path as the production 8/16/32 values), churns distinct glyphs, and asserts no pageerror, pages.length <= texture capacity, and an intact pinned header. RED today: 4x TypeError from GlyphRenderer.render.
@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.