Skip to content

Commit

Permalink
fix: Occasional crash when switching fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Feb 18, 2025
1 parent c39ae84 commit d3c2516
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 7 additions & 5 deletions main/gui/source/window/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ namespace hex {
}

void Window::frameBegin() {
// Run all deferred calls
TaskManager::runDeferredCalls();

ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplGlfw_NewFrame();

Expand All @@ -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();
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -682,9 +687,6 @@ namespace hex {
return banner->shouldClose();
});
}

// Run all deferred calls
TaskManager::runDeferredCalls();
}

void Window::frame() {
Expand Down
4 changes: 3 additions & 1 deletion plugins/fonts/source/library_fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit d3c2516

Please sign in to comment.