Skip to content

Commit fd2ceef

Browse files
committed
Fixed crash caused by fonts having ascii character sets; imgui can't load the font from disk
1 parent 4703176 commit fd2ceef

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

GWToolboxdll/Utils/FontLoader.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,12 @@ namespace {
321321
cfg.OversampleH = 1; // OversampleH = 2 for base text size (harder to read if OversampleH < 2)
322322
cfg.OversampleV = 1;
323323

324+
// Always load the defualt font
324325
cfg.MergeMode = false;
325-
if (first_only) {
326-
atlas->AddFontFromMemoryCompressedTTF(toolbox_default_font_compressed_data, toolbox_default_font_compressed_size, size, &cfg, toolbox_default_font_glyph_ranges);
327-
}
328-
else {
326+
atlas->AddFontFromMemoryCompressedTTF(toolbox_default_font_compressed_data, toolbox_default_font_compressed_size, size, &cfg, toolbox_default_font_glyph_ranges);
327+
328+
if(!first_only) {
329+
// Load more fonts from disk, overriding glyph ranges from original
329330
for (const auto& font : GetFontData()) {
330331
void* data;
331332
size_t data_size;
@@ -334,8 +335,10 @@ namespace {
334335
const auto path = Resources::GetPath(font.font_name);
335336
data = ImFileLoadToMemory(path.string().c_str(), "rb", &data_size, 0);
336337

338+
if (!data)
339+
continue; // Failed to load data from disk
340+
cfg.MergeMode = true;
337341
atlas->AddFontFromMemoryTTF(data, data_size, size, &cfg, font.glyph_ranges.data());
338-
cfg.MergeMode = true; // for all but the first
339342
}
340343
}
341344
if (size <= 20.f) {

0 commit comments

Comments
 (0)