Skip to content

Commit 874d192

Browse files
authored
Avoid throwing in CGUIElement::SetFont when the font name is unknown (#4868)
#### Summary Probe `CEGUI::FontManager::isFontPresent` before calling `setFont` in `CGUIElement_Impl::SetFont`, so unknown font names return `false` directly. #### Motivation Avoid an unnecessary throw on a hot path. #### Checklist * [x] Your code should follow the [coding guidelines](https://wiki.multitheftauto.com/index.php?title=Coding_guidelines). * [x] Smaller pull requests are easier to review. If your pull request is beefy, your pull request should be reviewable commit-by-commit.
1 parent fcce26d commit 874d192

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

Client/gui/CGUIElement_Impl.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,12 @@ void CGUIElement_Impl::CorrectEdges()
398398

399399
bool CGUIElement_Impl::SetFont(const char* szFontName)
400400
{
401+
if (szFontName != nullptr && *szFontName != '\0')
402+
{
403+
if (!CEGUI::FontManager::getSingleton().isFontPresent(CEGUI::String(szFontName)))
404+
return false;
405+
}
406+
401407
try
402408
{
403409
m_pWindow->setFont(CEGUI::String(szFontName));

0 commit comments

Comments
 (0)