Skip to content

Commit 14b6a71

Browse files
authored
Merge pull request #5615 from Tyriar/5585
Fix stack overflow in webgl page merge logic
2 parents 2521bab + c24eb60 commit 14b6a71

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

addons/addon-webgl/src/TextureAtlas.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,17 @@ export class TextureAtlas implements ITextureAtlas {
176176

177177
// Gather details of the merge
178178
const mergingPages = pagesBySize.slice(sameSizeI, sameSizeI + 4);
179+
180+
// Only proceed with merge if we have exactly 4 same-sized pages. If not, we cannot
181+
// effectively reduce page count and merging would cause issues.
182+
if (mergingPages.length < 4 || mergingPages.some(p => p.canvas.width !== mergingPages[0].canvas.width)) {
183+
const newPage = new AtlasPage(this._document, this._textureSize);
184+
this._pages.push(newPage);
185+
this._activePages.push(newPage);
186+
this._onAddTextureAtlasCanvas.fire(newPage.canvas);
187+
return newPage;
188+
}
189+
179190
const sortedMergingPagesIndexes = mergingPages.map(e => e.glyphs[0].texturePage).sort((a, b) => a > b ? 1 : -1);
180191
const mergedPageIndex = this.pages.length - mergingPages.length;
181192

0 commit comments

Comments
 (0)