fix: Crashes when font failed to be loaded

This commit is contained in:
WerWolv
2025-07-31 23:13:50 +02:00
parent bb6ea5f1e5
commit a2c4aefced
2 changed files with 7 additions and 3 deletions

View File

@@ -24,6 +24,7 @@ namespace hex::fonts::loader {
ImFontConfig config;
config.MergeMode = false;
config.SizePixels = settings.getFontSize();
config.Flags |= ImFontFlags_NoLoadError;
std::memcpy(config.Name, name.get().c_str(), std::min(name.get().size(), sizeof(config.Name) - 1));

View File

@@ -25,21 +25,24 @@ namespace hex::fonts {
return true;
}
ImFontConfig config = {};
config.FontDataOwnedByAtlas = true;
config.Flags |= ImFontFlags_NoLoadError;
auto atlas = ImGui::GetIO().Fonts;
auto it = s_previewFonts.find(fontPath);
if (it == s_previewFonts.end()) {
ImFont *font = nullptr;
if (fontPath == PixelPerfectFontName) {
font = atlas->AddFontDefault();
font = atlas->AddFontDefault(&config);
} else if (fontPath == SmoothFontName || fontPath.empty()) {
static auto jetbrainsFont = romfs::get("fonts/JetBrainsMono.ttf");
ImFontConfig config = {};
config.FontDataOwnedByAtlas = false;
font = atlas->AddFontFromMemoryTTF(const_cast<u8 *>(jetbrainsFont.data<u8>()), jetbrainsFont.size(), 0.0F, &config);
} else {
font = atlas->AddFontFromFileTTF(wolv::util::toUTF8String(fontPath).c_str());
font = atlas->AddFontFromFileTTF(wolv::util::toUTF8String(fontPath).c_str(), 0.0F, &config);
}
it = s_previewFonts.emplace(fontPath, font).first;