diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d8de4ff10..8b3ebf19d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ ### 🐞 Bug fixes - Fixes line flickering problem ([#5094](https://github.com/maplibre/maplibre-gl-js/pull/5094)) - Fix poor performance in Chrome related to passing matrices to WebGL ([#5072](https://github.com/maplibre/maplibre-gl-js/pull/5072)) +- Fix handling invalid glyph placement results along lines ([#5118](https://github.com/maplibre/maplibre-gl-js/pull/5118)) - _...Add new stuff here..._ ## 5.0.0-pre.7 diff --git a/src/symbol/projection.ts b/src/symbol/projection.ts index 4f00138639..84753a2190 100644 --- a/src/symbol/projection.ts +++ b/src/symbol/projection.ts @@ -465,9 +465,13 @@ function placeGlyphsAlongLine(args: GlyphLinePlacementArgs): GlyphLinePlacementR placedGlyphs = [firstAndLastGlyph.first]; for (let glyphIndex = symbol.glyphStartIndex + 1; glyphIndex < glyphEndIndex - 1; glyphIndex++) { - // Since first and last glyph fit on the line, we're sure that the rest of the glyphs can be placed - placedGlyphs.push(placeGlyphAlongLine(fontScale * glyphOffsetArray.getoffsetX(glyphIndex), lineOffsetX, lineOffsetY, flip, symbol.segment, - lineStartIndex, lineEndIndex, projectionContext, rotateToLine)); + // Since first and last glyph fit on the line, try placing the rest of the glyphs. + const placedGlyph = placeGlyphAlongLine(fontScale * glyphOffsetArray.getoffsetX(glyphIndex), lineOffsetX, lineOffsetY, flip, symbol.segment, + lineStartIndex, lineEndIndex, projectionContext, rotateToLine); + if (!placedGlyph) { + return {notEnoughRoom: true}; + } + placedGlyphs.push(placedGlyph); } placedGlyphs.push(firstAndLastGlyph.last); } else {