fix memory corruption in GenImageFontAtlas reallocation (#5602)

This commit is contained in:
moe li
2026-02-27 15:36:46 +08:00
committed by GitHub
parent 28e40d502a
commit f583674327

View File

@ -859,13 +859,14 @@ Image GenImageFontAtlas(const GlyphInfo *glyphs, Rectangle **glyphRecs, int glyp
{ {
TRACELOG(LOG_WARNING, "FONT: Updating atlas size to fit all characters"); TRACELOG(LOG_WARNING, "FONT: Updating atlas size to fit all characters");
// TODO: Increment atlas size (atlas.height*2) and continue adding glyphs // Update atlas size to fit all characters
int updatedAtlasHeight = atlas.height*2; int updatedAtlasHeight = atlas.height*2;
int updatedAtlasDataSize = atlas.width*atlas.height; int updatedAtlasDataSize = atlas.width*updatedAtlasHeight;
unsigned char *updatedAtlasData = (unsigned char *)RL_CALLOC(updatedAtlasDataSize, 1); unsigned char *updatedAtlasData = (unsigned char *)RL_CALLOC(updatedAtlasDataSize, 1);
memcpy(updatedAtlasData, atlas.data, atlasDataSize); memcpy(updatedAtlasData, atlas.data, atlasDataSize);
RL_FREE(atlas.data); RL_FREE(atlas.data);
atlas.data = updatedAtlasData;
atlas.height = updatedAtlasHeight; atlas.height = updatedAtlasHeight;
atlasDataSize = updatedAtlasDataSize; atlasDataSize = updatedAtlasDataSize;
} }