From fddc81ec0accad88e9a04594be0b41f6d5dc9094 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Mon, 11 May 2026 22:57:15 +0200 Subject: [PATCH] Special case for zero-byte prewarm --- lib/EpdFont/FontDecompressor.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/EpdFont/FontDecompressor.cpp b/lib/EpdFont/FontDecompressor.cpp index 8dbf2ba9..ee8215c2 100644 --- a/lib/EpdFont/FontDecompressor.cpp +++ b/lib/EpdFont/FontDecompressor.cpp @@ -259,6 +259,10 @@ int FontDecompressor::prewarmCache(const EpdFontData* fontData, const char* utf8 int32_t glyphIdx = findGlyphIndex(fontData, cp); if (glyphIdx < 0) continue; + const EpdGlyph& glyph = fontData->glyph[glyphIdx]; + // Whitespace/empty glyphs have no bitmap payload and do not need prewarm storage. + if (glyph.dataLength == 0 || glyph.width == 0 || glyph.height == 0) continue; + // Deduplicate against already prewarmed slots bool alreadyCached = false; for (uint8_t s = 0; s < pageSlotCount; s++) { @@ -376,6 +380,12 @@ int FontDecompressor::prewarmCache(const EpdFontData* fontData, const char* utf8 stats.uniqueGroupsAccessed = groupCount; + // Safety: if the collected glyph set has no bitmap payload, skip slot allocation. + if (totalBytes == 0) { + LOG_DBG("FDC", "Prewarm skipped: %u glyphs but 0 bitmap bytes", glyphCount); + return 0; + } + // Sort neededGroups by ascending group index so flash reads are sequential. // Uses insertion sort — groupCount is bounded at 128, typically <14 for Latin fonts. for (uint8_t i = 1; i < groupCount; i++) {