fix: Occasional crash when switching fonts

This commit is contained in:
WerWolv
2025-02-18 21:50:51 +01:00
parent c39ae84922
commit d3c2516f5f
2 changed files with 10 additions and 6 deletions

View File

@@ -334,6 +334,9 @@ namespace hex {
}
void Window::frameBegin() {
// Run all deferred calls
TaskManager::runDeferredCalls();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();
@@ -353,7 +356,7 @@ namespace hex {
}
{
const auto &font = ImHexApi::Fonts::getFont("hex.fonts.font.default");
auto font = ImHexApi::Fonts::getFont("hex.fonts.font.default");
if (font == nullptr) {
const auto &io = ImGui::GetIO();
@@ -362,13 +365,15 @@ namespace hex {
ImFontConfig cfg;
cfg.OversampleH = cfg.OversampleV = 1, cfg.PixelSnapH = true;
cfg.SizePixels = ImHexApi::Fonts::DefaultFontSize;
io.Fonts->AddFontDefault(&cfg);
font = io.Fonts->AddFontDefault(&cfg);
ImGui_ImplOpenGL3_CreateFontsTexture();
io.Fonts->ClearInputData();
io.Fonts->ClearTexData();
} else {
currentFont = font->ContainerAtlas;
}
ImGui::SetCurrentFont(font);
}
}
@@ -682,9 +687,6 @@ namespace hex {
return banner->shouldClose();
});
}
// Run all deferred calls
TaskManager::runDeferredCalls();
}
void Window::frame() {

View File

@@ -65,7 +65,9 @@ namespace hex::fonts {
return;
}
loadFont(widget, name, &font, ImHexApi::System::getGlobalScale() * ImHexApi::System::getBackingScaleFactor());
TaskManager::doLater([&name, &font, &widget] {
loadFont(widget, name, &font, ImHexApi::System::getGlobalScale() * ImHexApi::System::getBackingScaleFactor());
});
});
loadFont(widget.getWidget(), name, &font, ImHexApi::System::getGlobalScale() * ImHexApi::System::getBackingScaleFactor());