Update rtext.c

This commit is contained in:
Ray 2026-08-26 19:46:45 +02:00
commit ba0ac542c5

View file

@ -417,9 +417,6 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
int charSpacing = 0; int charSpacing = 0;
int lineSpacing = 0; int lineSpacing = 0;
int x = 0;
int y = 0;
// Allocate a temporal arrays for glyphs data measures, // Allocate a temporal arrays for glyphs data measures,
// once the actual number of glyphs is obtained, copy data to a sized array // once the actual number of glyphs is obtained, copy data to a sized array
int tempCharValues[MAX_GLYPHS_FROM_IMAGE] = { 0 }; int tempCharValues[MAX_GLYPHS_FROM_IMAGE] = { 0 };
@ -428,6 +425,8 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
Color *pixels = LoadImageColors(image); Color *pixels = LoadImageColors(image);
// Parse image data to get charSpacing and lineSpacing // Parse image data to get charSpacing and lineSpacing
int x = 0;
int y = 0;
for (y = 0; y < image.height; y++) for (y = 0; y < image.height; y++)
{ {
for (x = 0; x < image.width; x++) for (x = 0; x < image.width; x++)
@ -438,9 +437,11 @@ Font LoadFontFromImage(Image image, Color key, int firstChar)
if (!COLOR_EQUAL(pixels[y*image.width + x], key)) break; if (!COLOR_EQUAL(pixels[y*image.width + x], key)) break;
} }
if ((x == 0) || (y == 0)) { // Security check
UnloadImageColors(pixels); // Unload pixel colors to prevent memory leak if ((x == 0) || (y == 0))
return font; // Security check {
UnloadImageColors(pixels);
return font;
} }
charSpacing = x; charSpacing = x;