From d8ae03d2818e8c39befda7bf158122c709ae9a69 Mon Sep 17 00:00:00 2001 From: Alexis Murzeau Date: Sat, 27 Aug 2022 00:55:40 +0200 Subject: [PATCH] Fix crash when the font file doesn't exist --- SpaceCadetPinball/imgui_draw.cpp | 2 +- SpaceCadetPinball/winmain.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/SpaceCadetPinball/imgui_draw.cpp b/SpaceCadetPinball/imgui_draw.cpp index 5e52dee..05d4b6d 100644 --- a/SpaceCadetPinball/imgui_draw.cpp +++ b/SpaceCadetPinball/imgui_draw.cpp @@ -2141,7 +2141,7 @@ ImFont* ImFontAtlas::AddFontFromFileTTF(const char* filename, float size_pixels, void* data = ImFileLoadToMemory(filename, "rb", &data_size, 0); if (!data) { - IM_ASSERT_USER_ERROR(0, "Could not load font file!"); + // IM_ASSERT_USER_ERROR(0, "Could not load font file!"); return NULL; } ImFontConfig font_cfg = font_cfg_template ? *font_cfg_template : ImFontConfig(); diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index e5c1065..5759d46 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -125,7 +125,10 @@ int winmain::WinMain(LPCSTR lpCmdLine) fontConfig.OversampleV = 2; fontConfig.OversampleH = 8; - io.Fonts->AddFontFromFileTTF(Options.FontFileName.c_str(), 13.f, &fontConfig, ranges.Data); + if(!io.Fonts->AddFontFromFileTTF(Options.FontFileName.c_str(), 13.f, &fontConfig, ranges.Data)) { + // Font loading failed, load default font instead + io.Fonts->AddFontDefault(); + } io.Fonts->Build(); ImGuiSDL::Initialize(renderer, 0, 0);