Skip to content

Commit 8c9db85

Browse files
committed
fix(font): Add null check in W3DDisplayString::setFont to prevent crash
1 parent 87c471f commit 8c9db85

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ void W3DDisplayString::setFont( GameFont *font )
300300
// set the font in our renderer
301301
m_textRenderer.Set_Font( static_cast<FontCharsClass *>(m_font->fontData) );
302302

303-
m_textRendererHotKey.Set_Font( static_cast<FontCharsClass *>(TheFontLibrary->getFont(font->nameString,font->pointSize, TRUE)->fontData) );
303+
// TheSuperHackers @fix bobtista 30/01/2026 Check for null before dereferencing to prevent crash if font loading fails
304+
GameFont *boldFont = TheFontLibrary->getFont(font->nameString, font->pointSize, TRUE);
305+
if (boldFont != nullptr)
306+
m_textRendererHotKey.Set_Font( static_cast<FontCharsClass *>(boldFont->fontData) );
304307
// recompute extents for text with new font
305308
computeExtents();
306309

GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DDisplayString.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,10 @@ void W3DDisplayString::setFont( GameFont *font )
300300
// set the font in our renderer
301301
m_textRenderer.Set_Font( static_cast<FontCharsClass *>(m_font->fontData) );
302302

303-
m_textRendererHotKey.Set_Font( static_cast<FontCharsClass *>(TheFontLibrary->getFont(font->nameString,font->pointSize, TRUE)->fontData) );
303+
// TheSuperHackers @fix bobtista 30/01/2026 Check for null before dereferencing to prevent crash if font loading fails
304+
GameFont *boldFont = TheFontLibrary->getFont(font->nameString, font->pointSize, TRUE);
305+
if (boldFont != nullptr)
306+
m_textRendererHotKey.Set_Font( static_cast<FontCharsClass *>(boldFont->fontData) );
304307
// recompute extents for text with new font
305308
computeExtents();
306309

0 commit comments

Comments
 (0)