Added security check in case init fails #1135
This commit is contained in:
parent
2344941974
commit
4af4483f5f
1 changed files with 70 additions and 67 deletions
11
src/text.c
11
src/text.c
|
@ -504,10 +504,11 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
|
|||
|
||||
if (fileData != NULL)
|
||||
{
|
||||
// Init font for data reading
|
||||
stbtt_fontinfo fontInfo;
|
||||
if (!stbtt_InitFont(&fontInfo, fileData, 0)) TRACELOG(LOG_WARNING, "Failed to init font!");
|
||||
int genFontChars = false;
|
||||
stbtt_fontinfo fontInfo = { 0 };
|
||||
|
||||
if (stbtt_InitFont(&fontInfo, fileData, 0)) // Init font for data reading
|
||||
{
|
||||
// Calculate font scale factor
|
||||
float scaleFactor = stbtt_ScaleForPixelHeight(&fontInfo, (float)fontSize);
|
||||
|
||||
|
@ -521,7 +522,7 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
|
|||
|
||||
// Fill fontChars in case not provided externally
|
||||
// NOTE: By default we fill charsCount consecutevely, starting at 32 (Space)
|
||||
int genFontChars = false;
|
||||
|
||||
if (fontChars == NULL)
|
||||
{
|
||||
fontChars = (int *)RL_MALLOC(charsCount*sizeof(int));
|
||||
|
@ -585,6 +586,8 @@ CharInfo *LoadFontData(const char *fileName, int fontSize, int *fontChars, int c
|
|||
TRACELOGD("Character offsetY: %i", (int)((float)ascent*scaleFactor) + chY1);
|
||||
*/
|
||||
}
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "Failed to init font!");
|
||||
|
||||
RL_FREE(fileData);
|
||||
if (genFontChars) RL_FREE(fontChars);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue