From 97023def48c4be1e27bbaab70242521dd0d829df Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 17 Feb 2026 18:45:14 +0100 Subject: [PATCH] REVIEWED: `GenImageFontAtlas()`, scale image to fit all characters, in case it fails size estimation #5542 --- src/rtext.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/rtext.c b/src/rtext.c index 8e7fafec2..0fd2d8e6b 100644 --- a/src/rtext.c +++ b/src/rtext.c @@ -796,7 +796,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp if (glyphs == NULL) { - TRACELOG(LOG_WARNING, "FONT: Provided chars info not valid, returning empty image atlas"); + TRACELOG(LOG_WARNING, "FONT: Provided glyphs info not valid, returning empty image atlas"); return atlas; } @@ -881,16 +881,17 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp if (offsetY > (atlas.height - fontSize - padding)) { - for (int j = i + 1; j < glyphCount; j++) - { - TRACELOG(LOG_WARNING, "FONT: Failed to package character (0x%02x)", glyphs[j].value); - // Make sure remaining recs contain valid data - recs[j].x = 0; - recs[j].y = 0; - recs[j].width = 0; - recs[j].height = 0; - } - break; // Break for() loop, stop processing glyphs + TRACELOG(LOG_WARNING, "FONT: Updating atlas size to fit all characters"); + + // TODO: Increment atlas size (atlas.height*2) and continue adding glyphs + int updatedAtlasHeight = atlas.height*2; + int updatedAtlasDataSize = atlas.width*atlas.height; + unsigned char *updatedAtlasData = (unsigned char *)RL_CALLOC(updatedAtlasDataSize, 1); + + memcpy(updatedAtlasData, atlas.data, atlasDataSize); + RL_FREE(atlas.data); + atlas.height = updatedAtlasHeight; + atlasDataSize = updatedAtlasDataSize; } } @@ -967,7 +968,7 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp } } } - else TRACELOG(LOG_WARNING, "FONT: Failed to package character (0x%02x)", glyphs[i].value); + else TRACELOG(LOG_WARNING, "FONT: Failed to package glyph (0x%02x)", glyphs[i].value); } RL_FREE(rects);