1
0
mirror of synced 2025-02-02 12:27:25 +01:00

fix: Crash when no plugins were loaded

This commit is contained in:
WerWolv 2025-02-01 18:08:47 +01:00
parent 0c6fa768ea
commit e9bf1a9f7a
2 changed files with 18 additions and 15 deletions

View File

@ -529,19 +529,7 @@ namespace hex::init {
cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true; cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true;
cfg.SizePixels = ImHexApi::Fonts::DefaultFontSize; cfg.SizePixels = ImHexApi::Fonts::DefaultFontSize;
io.Fonts->AddFontDefault(&cfg); io.Fonts->AddFontDefault(&cfg);
ImGui_ImplOpenGL3_CreateFontsTexture();
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);
} }
// Don't save window settings for the splash screen // Don't save window settings for the splash screen

View File

@ -340,14 +340,29 @@ namespace hex {
auto &currentFont = ImGui::GetIO().Fonts; auto &currentFont = ImGui::GetIO().Fonts;
for (const auto &[name, font] : fontDefinitions) { for (const auto &[name, font] : fontDefinitions) {
// If the texture for this atlas has been built already, don't do it again // 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; continue;
currentFont = font->ContainerAtlas; currentFont = font->ContainerAtlas;
ImGui_ImplOpenGL3_CreateFontsTexture(); 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 // Start new ImGui Frame