1
0
mirror of synced 2025-02-17 18:59:21 +01:00

fix: Crash when loading bad font

This commit is contained in:
WerWolv 2023-07-22 19:35:58 +02:00
parent 8aec382440
commit 564ae6dd8c
2 changed files with 10 additions and 5 deletions

View File

@ -193,6 +193,8 @@ namespace hex::init {
}
static bool loadFontsImpl(bool loadUnicode) {
const float defaultFontSize = ImHexApi::System::DefaultFontSize * std::round(ImHexApi::System::getGlobalScale());
// Load font related settings
{
std::fs::path fontFile = ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.font_path", "");
@ -215,7 +217,7 @@ namespace hex::init {
ImHexApi::System::impl::setCustomFontPath(fontFile);
// If a custom font has been loaded now, also load the font size
float fontSize = ImHexApi::System::DefaultFontSize * std::round(ImHexApi::System::getGlobalScale());
float fontSize = defaultFontSize;
if (!fontFile.empty()) {
fontSize = ContentRegistry::Settings::read("hex.builtin.setting.font", "hex.builtin.setting.font.font_size", 13) * ImHexApi::System::getGlobalScale();
}
@ -281,7 +283,13 @@ namespace hex::init {
fonts->Clear();
fonts->AddFontDefault(&cfg);
} else {
fonts->AddFontFromFileTTF(wolv::util::toUTF8String(fontFile).c_str(), 0, &cfg, ranges.Data);
auto font = fonts->AddFontFromFileTTF(wolv::util::toUTF8String(fontFile).c_str(), 0, &cfg, ranges.Data);
if (font == nullptr || font->ContainerAtlas == nullptr) {
ImHexApi::System::impl::setFontSize(defaultFontSize);
cfg.SizePixels = defaultFontSize;
fonts->Clear();
fonts->AddFontDefault(&cfg);
}
}
// Merge all fonts into one big font atlas

View File

@ -180,9 +180,6 @@ namespace hex::plugin::builtin {
if (ImGui::Combo(name.data(), &selection, scaling, IM_ARRAYSIZE(scaling))) {
setting = selection;
ImHexApi::System::restartImHex();
return true;
}