From 7b346dbbe123b5ea89b0d46e388b4dc68c3e72a0 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 15 Aug 2020 11:32:23 +0200 Subject: [PATCH] Review issue with .fnt -> .png path #1351 When .fnt file is in the .exe path, image path was wrongly calculated --- src/text.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/text.c b/src/text.c index 51fee3eb..e8ee28e8 100644 --- a/src/text.c +++ b/src/text.c @@ -1703,6 +1703,9 @@ static Font LoadBMFont(const char *fileName) int base = 0; // Useless data char *fileText = LoadFileText(fileName); + + if (fileText == NULL) return font; + char *fileTextPtr = fileText; // NOTE: We skip first line, it contains no useful information @@ -1734,20 +1737,24 @@ static Font LoadBMFont(const char *fileName) TRACELOGD(" > Chars count: %i", charsCount); // Compose correct path using route of .fnt file (fileName) and imFileName - char *texPath = NULL; + char *imPath = NULL; char *lastSlash = NULL; lastSlash = strrchr(fileName, '/'); if (lastSlash == NULL) lastSlash = strrchr(fileName, '\\'); - // NOTE: We need some extra space to avoid memory corruption on next allocations! - texPath = RL_CALLOC(TextLength(fileName) - TextLength(lastSlash) + TextLength(imFileName) + 4, 1); - memcpy(texPath, fileName, TextLength(fileName) - TextLength(lastSlash) + 1); - memcpy(texPath + TextLength(fileName) - TextLength(lastSlash) + 1, imFileName, TextLength(imFileName)); + if (lastSlash != NULL) + { + // NOTE: We need some extra space to avoid memory corruption on next allocations! + imPath = RL_CALLOC(TextLength(fileName) - TextLength(lastSlash) + TextLength(imFileName) + 4, 1); + memcpy(imPath, fileName, TextLength(fileName) - TextLength(lastSlash) + 1); + memcpy(imPath + TextLength(fileName) - TextLength(lastSlash) + 1, imFileName, TextLength(imFileName)); + } + else imPath = imFileName; - TRACELOGD(" > Texture loading path: %s", texPath); + TRACELOGD(" > Image loading path: %s", imPath); - Image imFont = LoadImage(texPath); + Image imFont = LoadImage(imPath); if (imFont.format == UNCOMPRESSED_GRAYSCALE) { @@ -1772,7 +1779,7 @@ static Font LoadBMFont(const char *fileName) font.texture = LoadTextureFromImage(imFont); - RL_FREE(texPath); + if (lastSlash != NULL) RL_FREE(imPath); // Fill font characters info data font.baseSize = fontSize;