Review issue with .fnt -> .png path #1351
When .fnt file is in the .exe path, image path was wrongly calculated
This commit is contained in:
parent
902a97f540
commit
7b346dbbe1
21
src/text.c
21
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, '\\');
|
||||
|
||||
if (lastSlash != NULL)
|
||||
{
|
||||
// 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));
|
||||
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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user