From e9bf1a9f7ad53c9e2e9c87f7da0313a8fbb2dd9a Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 1 Feb 2025 18:08:47 +0100 Subject: [PATCH] fix: Crash when no plugins were loaded --- main/gui/source/init/splash_window.cpp | 14 +------------- main/gui/source/window/window.cpp | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/main/gui/source/init/splash_window.cpp b/main/gui/source/init/splash_window.cpp index bc47e0e7d..71916339d 100644 --- a/main/gui/source/init/splash_window.cpp +++ b/main/gui/source/init/splash_window.cpp @@ -529,19 +529,7 @@ namespace hex::init { cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true; cfg.SizePixels = ImHexApi::Fonts::DefaultFontSize; io.Fonts->AddFontDefault(&cfg); - - std::uint8_t *px; - int w, h; - io.Fonts->GetTexDataAsAlpha8(&px, &w, &h); - - // Create new font atlas - GLuint tex; - glGenTextures(1, &tex); - glBindTexture(GL_TEXTURE_2D, tex); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, w, h, 0, GL_ALPHA, GL_UNSIGNED_BYTE, px); - io.Fonts->SetTexID(tex); + ImGui_ImplOpenGL3_CreateFontsTexture(); } // Don't save window settings for the splash screen diff --git a/main/gui/source/window/window.cpp b/main/gui/source/window/window.cpp index e6f3fcb92..158ba0e5d 100644 --- a/main/gui/source/window/window.cpp +++ b/main/gui/source/window/window.cpp @@ -340,14 +340,29 @@ namespace hex { auto ¤tFont = ImGui::GetIO().Fonts; for (const auto &[name, font] : fontDefinitions) { // If the texture for this atlas has been built already, don't do it again - if (font->ContainerAtlas->TexID != 0) + if (font == nullptr || font->ContainerAtlas->TexID != 0) continue; currentFont = font->ContainerAtlas; ImGui_ImplOpenGL3_CreateFontsTexture(); } - currentFont = ImHexApi::Fonts::getFont("hex.fonts.font.default")->ContainerAtlas; + { + const auto &font = ImHexApi::Fonts::getFont("hex.fonts.font.default"); + + if (font == nullptr) { + const auto &io = ImGui::GetIO(); + io.Fonts->Clear(); + + ImFontConfig cfg; + cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true; + cfg.SizePixels = ImHexApi::Fonts::DefaultFontSize; + io.Fonts->AddFontDefault(&cfg); + ImGui_ImplOpenGL3_CreateFontsTexture(); + } else { + currentFont = font->ContainerAtlas; + } + } } // Start new ImGui Frame