Skip to content

Commit 879b1f4

Browse files
authored
Merge pull request #7121 from Goober5000/fix_font_crash
fix a font crash
2 parents 2af19b6 + 406f8e5 commit 879b1f4

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

code/graphics/software/font.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace
7171
}
7272
}
7373

74-
void parse_nvg_font(const SCP_string& fontFilename)
74+
bool parse_nvg_font(const SCP_string& fontFilename)
7575
{
7676
float size = 8.0f;
7777
SCP_string fontStr;
@@ -122,27 +122,27 @@ namespace
122122
if (hasName)
123123
{
124124
error_display(0, "Font with name \"%s\" is already present! Font names have to be unique!", fontStr.c_str());
125-
return;
125+
return false;
126126
}
127127
else
128128
{
129129
error_display(0, "Found font with same default name (\"%s\"). This is most likely a duplicate.", fontStr.c_str());
130-
return;
130+
return false;
131131
}
132132
}
133133

134134
auto nvgPair = FontManager::loadNVGFont(fontFilename, size);
135135
auto nvgFont = nvgPair.first;
136136

137-
// Now we can set the auto size behavior which is used for special character rendering
138-
nvgFont->setAutoScaleBehavior(autoSize);
139-
140137
if (nvgFont == NULL)
141138
{
142139
error_display(0, "Couldn't load font \"%s\".", fontFilename.c_str());
143-
return;
140+
return false;
144141
}
145142

143+
// Now we can set the auto size behavior which is used for special character rendering
144+
nvgFont->setAutoScaleBehavior(autoSize);
145+
146146
if (optional_string("+Can Scale:")) {
147147
bool temp;
148148

@@ -289,17 +289,19 @@ namespace
289289

290290
// Make sure that the height is not invalid
291291
nvgFont->computeFontMetrics();
292+
293+
return true;
292294
}
293295

294-
void parse_vfnt_font(const SCP_string& fontFilename)
296+
bool parse_vfnt_font(const SCP_string& fontFilename)
295297
{
296298
auto vfntPair = FontManager::loadVFNTFont(fontFilename);
297299
auto font = vfntPair.first;
298300

299301
if (font == NULL)
300302
{
301303
error_display(0, "Couldn't load font\"%s\".", fontFilename.c_str());
302-
return;
304+
return false;
303305
}
304306

305307
SCP_string fontName;
@@ -421,8 +423,11 @@ namespace
421423

422424
font->setBottomOffset(temp);
423425
}
426+
424427
// Make sure that the height is not invalid
425428
font->computeFontMetrics();
429+
430+
return true;
426431
}
427432

428433
void font_parse_setup(const char *fileName)
@@ -464,23 +469,27 @@ namespace
464469

465470
while (parse_type(type, fontName))
466471
{
472+
bool parsed = false;
473+
467474
switch (type)
468475
{
469476
case VFNT_FONT:
470477
if (Unicode_text_mode) {
471478
skipped_font_names.push_back(fontName);
472-
skip_to_start_of_string_one_of({"$TrueType:", "$Font:", "#End"});
473479
} else {
474-
parse_vfnt_font(fontName);
480+
parsed = parse_vfnt_font(fontName);
475481
}
476482
break;
477483
case NVG_FONT:
478-
parse_nvg_font(fontName);
484+
parsed = parse_nvg_font(fontName);
479485
break;
480486
default:
481487
error_display(0, "Unknown font type %d! Get a coder!", (int)type);
482488
break;
483489
}
490+
491+
if (!parsed)
492+
skip_to_start_of_string_one_of({ "$TrueType:", "$Font:", "#End" });
484493
}
485494

486495
// check if we skipped any fonts

0 commit comments

Comments
 (0)