File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments