summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2020-08-15 11:32:23 +0200
committerRay <[email protected]>2020-08-15 11:32:23 +0200
commit7b346dbbe123b5ea89b0d46e388b4dc68c3e72a0 (patch)
tree79b439ad6147a9af6ed8bd69993f5135df04ecde
parent902a97f5402065f4f0719aee482da14ae649c5c8 (diff)
downloadraylib-7b346dbbe123b5ea89b0d46e388b4dc68c3e72a0.tar.gz
raylib-7b346dbbe123b5ea89b0d46e388b4dc68c3e72a0.zip
Review issue with .fnt -> .png path #1351
When .fnt file is in the .exe path, image path was wrongly calculated
-rw-r--r--src/text.c23
1 files 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;