mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-05 19:08:13 +00:00
Merge pull request #4918 from JeffM2501/default_font_image_leaks
[rText] Fix issues with default font being used before InitWindow in the image API.
This commit is contained in:
21
src/rtext.c
21
src/rtext.c
@@ -161,6 +161,10 @@ extern void LoadFontDefault(void)
|
|||||||
{
|
{
|
||||||
#define BIT_CHECK(a,b) ((a) & (1u << (b)))
|
#define BIT_CHECK(a,b) ((a) & (1u << (b)))
|
||||||
|
|
||||||
|
// check to see if we have allready allocated the font for an image, and if we don't need to upload, then just return
|
||||||
|
if (defaultFont.glyphs != NULL && !isGpuReady)
|
||||||
|
return;
|
||||||
|
|
||||||
// NOTE: Using UTF-8 encoding table for Unicode U+0000..U+00FF Basic Latin + Latin-1 Supplement
|
// NOTE: Using UTF-8 encoding table for Unicode U+0000..U+00FF Basic Latin + Latin-1 Supplement
|
||||||
// Ref: http://www.utf8-chartable.de/unicode-utf8-table.pl
|
// Ref: http://www.utf8-chartable.de/unicode-utf8-table.pl
|
||||||
|
|
||||||
@@ -256,8 +260,19 @@ extern void LoadFontDefault(void)
|
|||||||
|
|
||||||
counter++;
|
counter++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isGpuReady) defaultFont.texture = LoadTextureFromImage(imFont);
|
if (isGpuReady)
|
||||||
|
{
|
||||||
|
defaultFont.texture = LoadTextureFromImage(imFont);
|
||||||
|
|
||||||
|
// we have already loaded the font glyph data an image, and the GPU is ready, we are done
|
||||||
|
// if we don't do this, we will leak memory by reallocating the glyphs and rects
|
||||||
|
if (defaultFont.glyphs != NULL)
|
||||||
|
{
|
||||||
|
UnloadImage(imFont);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Reconstruct charSet using charsWidth[], charsHeight, charsDivisor, glyphCount
|
// Reconstruct charSet using charsWidth[], charsHeight, charsDivisor, glyphCount
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@@ -282,7 +297,7 @@ extern void LoadFontDefault(void)
|
|||||||
|
|
||||||
testPosX += (int)(defaultFont.recs[i].width + (float)charsDivisor);
|
testPosX += (int)(defaultFont.recs[i].width + (float)charsDivisor);
|
||||||
|
|
||||||
if (testPosX >= defaultFont.texture.width)
|
if (testPosX >= imFont.width)
|
||||||
{
|
{
|
||||||
currentLine++;
|
currentLine++;
|
||||||
currentPosX = 2*charsDivisor + charsWidth[i];
|
currentPosX = 2*charsDivisor + charsWidth[i];
|
||||||
|
Reference in New Issue
Block a user