@xterm/addon-webgl 0.20.0-beta.288 → 0.20.0-beta.289

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xterm/addon-webgl",
3
- "version": "0.20.0-beta.288",
3
+ "version": "0.20.0-beta.289",
4
4
  "author": {
5
5
  "name": "The xterm.js authors",
6
6
  "url": "https://xtermjs.org/"
@@ -23,8 +23,8 @@
23
23
  "prepublishOnly": "npm run package",
24
24
  "start": "node ../../demo/start"
25
25
  },
26
- "commit": "b1aee19ac6d6f4e4d11e4a10a3731b852956bdb7",
26
+ "commit": "ce2169485677951c7701129516cbb68e01330d86",
27
27
  "peerDependencies": {
28
- "@xterm/xterm": "^6.1.0-beta.289"
28
+ "@xterm/xterm": "^6.1.0-beta.290"
29
29
  }
30
30
  }
@@ -101,6 +101,7 @@ export class GlyphRenderer extends Disposable {
101
101
 
102
102
  private _atlas: ITextureAtlas | undefined;
103
103
  private _lastSeenPageLayoutVersion: number = -1;
104
+ private _pageOverflowWarned: boolean = false;
104
105
  private _activeBuffer: number = 0;
105
106
  private readonly _vertices: IVertices = {
106
107
  count: 0,
@@ -375,7 +376,13 @@ export class GlyphRenderer extends Disposable {
375
376
  // Bind the atlas page texture if they have changed. AtlasPage.version is globally
376
377
  // monotonic, so a page object swap at the same index (which happens after a page merge)
377
378
  // is detected by the same comparison.
378
- for (let i = 0; i < this._atlas.pages.length; i++) {
379
+ // Clamp defensively in case the atlas unexpectedly exceeds texture capacity.
380
+ const pageCount = Math.min(this._atlas.pages.length, this._atlasTextures.length);
381
+ if (this._atlas.pages.length > this._atlasTextures.length && !this._pageOverflowWarned) {
382
+ this._pageOverflowWarned = true;
383
+ this._logService.warn(`Atlas page count (${this._atlas.pages.length}) exceeds the renderer's texture capacity (${this._atlasTextures.length}), some glyphs will not render correctly`);
384
+ }
385
+ for (let i = 0; i < pageCount; i++) {
379
386
  if (this._atlas.pages[i].version !== this._atlasTextures[i].version) {
380
387
  this._bindAtlasPageTexture(gl, this._atlas, i);
381
388
  }
@@ -180,6 +180,8 @@ export class TextureAtlas implements ITextureAtlas {
180
180
  // Only proceed with merge if we have exactly 4 same-sized pages. If not, we cannot
181
181
  // effectively reduce page count and merging would cause issues.
182
182
  if (mergingPages.length < 4 || mergingPages.some(p => p.canvas.width !== mergingPages[0].canvas.width)) {
183
+ // Evict instead of adding a page beyond the renderer's texture capacity.
184
+ this._evictAllPages();
183
185
  const newPage = new AtlasPage(this._document, this._textureSize);
184
186
  this._pages.push(newPage);
185
187
  this._activePages.push(newPage);
@@ -202,7 +204,7 @@ export class TextureAtlas implements ITextureAtlas {
202
204
  // Add the new merged page to the end
203
205
  this.pages.push(mergedPage);
204
206
 
205
- // Request the model to be cleared to refresh all texture pages.
207
+ // Invalidate renderer models so all texture pages are refreshed.
206
208
  this._pageLayoutVersion++;
207
209
  this._onAddTextureAtlasCanvas.fire(mergedPage.canvas);
208
210
  }
@@ -254,6 +256,23 @@ export class TextureAtlas implements ITextureAtlas {
254
256
  }
255
257
  }
256
258
 
259
+ private _evictAllPages(): void {
260
+ const startTime = performance.now();
261
+ const pageCount = this._pages.length;
262
+ for (const page of this._pages) {
263
+ this._onRemoveTextureAtlasCanvas.fire(page.canvas);
264
+ page.canvas.remove();
265
+ }
266
+ this._pages.length = 0;
267
+ this._activePages.length = 0;
268
+ this._overflowSizePage = undefined;
269
+ this._cacheMap.clear();
270
+ this._cacheMapCombined.clear();
271
+ this._didWarmUp = false;
272
+ this._pageLayoutVersion++;
273
+ this._logService.debug(`Evicted ${pageCount} WebGL atlas pages in ${(performance.now() - startTime).toFixed(2)}ms`);
274
+ }
275
+
257
276
  public getRasterizedGlyphCombinedChar(chars: string, bg: number, fg: number, ext: number, restrictToCellHeight: boolean, domContainer: HTMLElement | undefined): IRasterizedGlyph {
258
277
  return this._getFromCacheMap(this._cacheMapCombined, chars, bg, fg, ext, restrictToCellHeight, domContainer);
259
278
  }
@@ -811,10 +830,14 @@ export class TextureAtlas implements ITextureAtlas {
811
830
  // Create a new page for oversized glyphs as they come up
812
831
  if (rasterizedGlyph.size.x > this._textureSize) {
813
832
  if (!this._overflowSizePage) {
833
+ // Make room for the oversized page without exceeding texture capacity.
834
+ if (TextureAtlas.maxAtlasPages && this._pages.length >= TextureAtlas.maxAtlasPages) {
835
+ this._evictAllPages();
836
+ }
814
837
  this._overflowSizePage = new AtlasPage(this._document, this._config.deviceMaxTextureSize);
815
838
  this.pages.push(this._overflowSizePage);
816
839
 
817
- // Request the model to be cleared to refresh all texture pages.
840
+ // Invalidate renderer models so all texture pages are refreshed.
818
841
  this._pageLayoutVersion++;
819
842
  this._onAddTextureAtlasCanvas.fire(this._overflowSizePage.canvas);
820
843
  }