diff --git a/addons/addon-webgl/src/GlyphRenderer.ts b/addons/addon-webgl/src/GlyphRenderer.ts index c8ab2f344..742f0879f 100644 --- a/addons/addon-webgl/src/GlyphRenderer.ts +++ b/addons/addon-webgl/src/GlyphRenderer.ts @@ -376,6 +376,7 @@ export class GlyphRenderer extends Disposable { // Bind the atlas page texture if they have changed. AtlasPage.version is globally // monotonic, so a page object swap at the same index (which happens after a page merge) // is detected by the same comparison. + // Clamp defensively in case the atlas unexpectedly exceeds texture capacity. const pageCount = Math.min(this._atlas.pages.length, this._atlasTextures.length); if (this._atlas.pages.length > this._atlasTextures.length && !this._pageOverflowWarned) { this._pageOverflowWarned = true; diff --git a/addons/addon-webgl/src/TextureAtlas.ts b/addons/addon-webgl/src/TextureAtlas.ts index 436aa553b..40d82df49 100644 --- a/addons/addon-webgl/src/TextureAtlas.ts +++ b/addons/addon-webgl/src/TextureAtlas.ts @@ -180,6 +180,7 @@ export class TextureAtlas implements ITextureAtlas { // Only proceed with merge if we have exactly 4 same-sized pages. If not, we cannot // effectively reduce page count and merging would cause issues. if (mergingPages.length < 4 || mergingPages.some(p => p.canvas.width !== mergingPages[0].canvas.width)) { + // Evict instead of adding a page beyond the renderer's texture capacity. this._evictAllPages(); const newPage = new AtlasPage(this._document, this._textureSize); this._pages.push(newPage); @@ -829,6 +830,7 @@ export class TextureAtlas implements ITextureAtlas { // Create a new page for oversized glyphs as they come up if (rasterizedGlyph.size.x > this._textureSize) { if (!this._overflowSizePage) { + // Make room for the oversized page without exceeding texture capacity. if (TextureAtlas.maxAtlasPages && this._pages.length >= TextureAtlas.maxAtlasPages) { this._evictAllPages(); }