From 7d9749d0effd8c5febdf7fd2dfcadbbdda147e72 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 17 Feb 2022 21:40:31 -0500 Subject: [PATCH] GUI: prevent crash when unable to load a font --- src/gui/gui.cpp | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2f2c59ac5..84acd5346 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -2901,7 +2901,17 @@ void FurnaceGUI::commitSettings() { applyUISettings(); ImGui_ImplSDLRenderer_DestroyFontsTexture(); - ImGui::GetIO().Fonts->Build(); + if (!ImGui::GetIO().Fonts->Build()) { + logE("error while building font atlas!\n"); + showError("error while loading fonts! please check your settings."); + ImGui::GetIO().Fonts->Clear(); + mainFont=ImGui::GetIO().Fonts->AddFontDefault(); + patFont=mainFont; + ImGui_ImplSDLRenderer_DestroyFontsTexture(); + if (!ImGui::GetIO().Fonts->Build()) { + logE("error again while building font atlas!\n"); + } + } } void FurnaceGUI::drawDebug() { @@ -6594,6 +6604,7 @@ void FurnaceGUI::applyUISettings() { logE("could not load icon font!\n"); } if (settings.mainFontSize==settings.patFontSize && settings.patFont<5 && builtinFontM[settings.patFont]==builtinFont[settings.mainFont]) { + logD("using main font for pat font.\n"); patFont=mainFont; } else { if (settings.patFont==6) { // custom font @@ -6729,6 +6740,18 @@ bool FurnaceGUI::init() { applyUISettings(); + if (!ImGui::GetIO().Fonts->Build()) { + logE("error while building font atlas!\n"); + showError("error while loading fonts! please check your settings."); + ImGui::GetIO().Fonts->Clear(); + mainFont=ImGui::GetIO().Fonts->AddFontDefault(); + patFont=mainFont; + ImGui_ImplSDLRenderer_DestroyFontsTexture(); + if (!ImGui::GetIO().Fonts->Build()) { + logE("error again while building font atlas!\n"); + } + } + strncpy(finalLayoutPath,(e->getConfigPath()+String(LAYOUT_INI)).c_str(),4095); prepareLayout();