Skip to content

Commit

Permalink
Fix /font command making the engine crash on further starts
Browse files Browse the repository at this point in the history
  • Loading branch information
lhog committed Jan 11, 2025
1 parent 6cde9cd commit 89cc993
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
19 changes: 17 additions & 2 deletions rts/Game/UnsyncedGameCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2548,8 +2548,23 @@ class FontActionExecutor : public IUnsyncedActionExecutor {
}

bool Execute(const UnsyncedAction& action) const final {
// FIXME: same file for both?
CglFont::LoadCustomFonts(action.GetArgs(), action.GetArgs());
auto args = CSimpleParser::Tokenize(action.GetArgs(), 1);
std::string newLargeFontFile;
std::string newSmallFontFile;
switch (args.size())
{
case 1: {
newSmallFontFile = std::move(args[0]);
} break;
case 2: {
newSmallFontFile = std::move(args[0]);
newLargeFontFile = std::move(args[1]);
} break;
default:
// nothing
break;
}
CglFont::LoadCustomFonts(newSmallFontFile, newLargeFontFile);
return true;
}
};
Expand Down
4 changes: 2 additions & 2 deletions rts/Rendering/Fonts/CFontTexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,11 @@ CFontTexture::CFontTexture(const std::string& fontfile, int size, int _outlinesi
}
catch (content_error& ex) {
LOG_L(L_ERROR, "[%s] %s (s=%d): %s", __func__, fontfile.c_str(), fontSize, ex.what());
return;
throw;
}

if (shFace == nullptr)
return;
throw content_error("Failed to load font file: " + fontfile);

FT_Face face = *shFace;

Expand Down
18 changes: 10 additions & 8 deletions rts/Rendering/Fonts/glFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ bool CglFont::LoadConfigFonts()
bool CglFont::LoadCustomFonts(const std::string& smallFontFile, const std::string& largeFontFile)
{
RECOIL_DETAILED_TRACY_ZONE;
auto newLargeFont = CglFont::LoadFont(largeFontFile, false);
auto newSmallFont = CglFont::LoadFont(smallFontFile, true);
if (auto newFont = CglFont::LoadFont(largeFontFile, false); newFont) {
font = newFont;

if (newLargeFont != nullptr && newSmallFont != nullptr) {
font = newLargeFont;
smallFont = newSmallFont;
LOG("[%s] loaded large font \"%s\"", __func__, newFont->GetFilePath().c_str());
configHandler->SetString( "FontFile", newFont->GetFilePath());
}

if (auto newFont = CglFont::LoadFont(smallFontFile, false); newFont) {
smallFont = newFont;

LOG("[%s] loaded fonts \"%s\" and \"%s\"", __func__, smallFontFile.c_str(), largeFontFile.c_str());
configHandler->SetString( "FontFile", largeFontFile);
configHandler->SetString("SmallFontFile", smallFontFile);
LOG("[%s] loaded small font \"%s\"", __func__, newFont->GetFilePath().c_str());
configHandler->SetString("SmallFontFile", newFont->GetFilePath());
}

return true;
Expand Down

0 comments on commit 89cc993

Please sign in to comment.