Pārlūkot izejas kodu

Review issue with .fnt -> .png path #1351

When .fnt file is in the .exe path, image path was wrongly calculated
pull/1357/head
Ray pirms 4 gadiem
vecāks
revīzija
7b346dbbe1
1 mainītis faili ar 15 papildinājumiem un 8 dzēšanām
  1. +15
    -8
      src/text.c

+ 15
- 8
src/text.c Parādīt failu

@ -1703,6 +1703,9 @@ static Font LoadBMFont(const char *fileName)
int base = 0; // Useless data int base = 0; // Useless data
char *fileText = LoadFileText(fileName); char *fileText = LoadFileText(fileName);
if (fileText == NULL) return font;
char *fileTextPtr = fileText; char *fileTextPtr = fileText;
// NOTE: We skip first line, it contains no useful information // 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); TRACELOGD(" > Chars count: %i", charsCount);
// Compose correct path using route of .fnt file (fileName) and imFileName // Compose correct path using route of .fnt file (fileName) and imFileName
char *texPath = NULL;
char *imPath = NULL;
char *lastSlash = NULL; char *lastSlash = NULL;
lastSlash = strrchr(fileName, '/'); lastSlash = strrchr(fileName, '/');
if (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) if (imFont.format == UNCOMPRESSED_GRAYSCALE)
{ {
@ -1772,7 +1779,7 @@ static Font LoadBMFont(const char *fileName)
font.texture = LoadTextureFromImage(imFont); font.texture = LoadTextureFromImage(imFont);
RL_FREE(texPath);
k">if (lastSlash != NULL) RL_FREE(imPath);
// Fill font characters info data // Fill font characters info data
font.baseSize = fontSize; font.baseSize = fontSize;

Notiek ielāde…
Atcelt
Saglabāt