Skip to content

Commit 21bd422

Browse files
committed
Properly handle invalid fonts and do not try to render them
1 parent 293e6f2 commit 21bd422

File tree

20 files changed

+95
-98
lines changed

20 files changed

+95
-98
lines changed

Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,8 @@ Render2DSentenceClass::Build_Sentence (const WCHAR *text, int *hkX, int *hkY)
11701170
return ;
11711171
}
11721172

1173+
if (Font == NULL)
1174+
return;
11731175

11741176
if(Centered && (WrapWidth > 0 || wcschr(text,L'\n')))
11751177
Build_Sentence_Centered(text, hkX, hkY);
@@ -1504,11 +1506,9 @@ FontCharsClass::Update_Current_Buffer (int char_width)
15041506
// Create_GDI_Font
15051507
//
15061508
////////////////////////////////////////////////////////////////////////////////////
1507-
void
1509+
bool
15081510
FontCharsClass::Create_GDI_Font (const char *font_name)
15091511
{
1510-
WWASSERT(PointSize > 0);
1511-
15121512
HDC screen_dc = ::GetDC ((HWND)WW3D::Get_Window());
15131513

15141514
const char *fontToUseForGenerals = "Arial";
@@ -1600,6 +1600,8 @@ FontCharsClass::Create_GDI_Font (const char *font_name)
16001600
if (doingGenerals) {
16011601
CharOverhang = 0;
16021602
}
1603+
1604+
return GDIFont != NULL && GDIBitmap != NULL;
16031605
}
16041606

16051607

@@ -1648,7 +1650,7 @@ FontCharsClass::Free_GDI_Font (void)
16481650
// Initialize_GDI_Font
16491651
//
16501652
////////////////////////////////////////////////////////////////////////////////////
1651-
void
1653+
bool
16521654
FontCharsClass::Initialize_GDI_Font (const char *font_name, int point_size, bool is_bold)
16531655
{
16541656
//
@@ -1666,8 +1668,7 @@ FontCharsClass::Initialize_GDI_Font (const char *font_name, int point_size, bool
16661668
//
16671669
// Create the actual font object
16681670
//
1669-
Create_GDI_Font (font_name);
1670-
return ;
1671+
return Create_GDI_Font (font_name);
16711672
}
16721673

16731674

Core/Libraries/Source/WWVegas/WW3D2/render2dsentence.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class FontCharsClass : public W3DMPO, public RefCountClass
8282
FontCharsClass *AlternateUnicodeFont;
8383

8484

85-
void Initialize_GDI_Font( const char *font_name, int point_size, bool is_bold );
85+
bool Initialize_GDI_Font( const char *font_name, int point_size, bool is_bold );
8686
bool Is_Font( const char *font_name, int point_size, bool is_bold );
8787
const char * Get_Name( void ) { return Name; }
8888

@@ -99,7 +99,7 @@ class FontCharsClass : public W3DMPO, public RefCountClass
9999
//
100100
// Private methods
101101
//
102-
void Create_GDI_Font( const char *font_name );
102+
bool Create_GDI_Font( const char *font_name );
103103
void Free_GDI_Font( void );
104104
const FontCharsClassCharDataStruct * Store_GDI_Char( WCHAR ch );
105105
void Update_Current_Buffer( int char_width );

Generals/Code/GameEngine/Source/GameClient/Credits.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ void CreditsManager::load(void )
166166
TheGlobalLanguageData->adjustFontSize(TheGlobalLanguageData->m_creditsNormalFont.size),
167167
TheGlobalLanguageData->m_creditsNormalFont.bold);
168168

169-
m_normalFontHeight = font->height;
169+
m_normalFontHeight = font ? font->height : 0;
170170
}
171171

172172
void CreditsManager::reset( void )

Generals/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/IMECandidate.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,14 @@ void IMECandidateTextAreaDraw( GameWindow *window, WinInstanceData *instData )
164164
return;
165165
}
166166

167-
GameFont *font = window->winGetFont() ;
168-
Int height;
167+
GameFont *font = window->winGetFont();
169168

170169
// set the font
171170
Dstring->setFont( font );
172171

173-
// cacl line height
174-
height = font->height + IMECandidateWindowLineSpacing;
172+
// calculate line height
173+
Int fontHeight = font ? font->height : 0;
174+
Int height = fontHeight + IMECandidateWindowLineSpacing;
175175

176176
// set the clip region
177177
Dstring->setClipRegion( &textRegion );

Generals/Code/GameEngine/Source/GameClient/GUI/GameWindowGlobal.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,9 @@ void GameWindowManager::winGetTextSize( GameFont *font, UnicodeString text,
185185
Int GameWindowManager::winFontHeight( GameFont *font )
186186
{
187187

188+
if (font == NULL)
189+
return 0;
190+
188191
return font->height;
189192

190193
}

Generals/Code/GameEngine/Source/GameClient/GUI/GameWindowManagerScript.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,9 @@ static Bool parseFont( const char *token, WinInstanceData *instData,
618618

619619
if( TheFontLibrary )
620620
{
621-
GameFont *font;
622-
623-
font = TheFontLibrary->getFont( AsciiString(fontName), fontSize, fontBold );
621+
GameFont *font = TheFontLibrary->getFont( AsciiString(fontName), fontSize, fontBold );
624622
if( font )
625623
instData->m_font = font;
626-
627624
}
628625

629626
return TRUE;

Generals/Code/GameEngine/Source/GameClient/InGameUI.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,8 +3618,10 @@ void InGameUI::postDraw( void )
36183618
m_uiMessages[ i ].displayString->draw( x, y, m_uiMessages[ i ].color, dropColor );
36193619

36203620
// increment text spot to next location
3621-
GameFont *font = m_uiMessages[ i ].displayString->getFont();
3622-
y += font->height;
3621+
if (GameFont *font = m_uiMessages[ i ].displayString->getFont())
3622+
{
3623+
y += font->height;
3624+
}
36233625

36243626
}
36253627

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/W3DGameFont.cpp

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -77,44 +77,28 @@ Bool W3DFontLibrary::loadFontData( GameFont *font )
7777
if( font == NULL )
7878
return FALSE;
7979

80+
const char* name = font->nameString.str();
81+
const Int size = font->pointSize;
82+
const Bool bold = font->bold;
83+
8084
// get the font data from the asset manager
81-
FontCharsClass *fontChar = WW3DAssetManager::Get_Instance()->Get_FontChars(
82-
font->nameString.str(), font->pointSize, font->bold ? true : false );
85+
FontCharsClass *fontChar = WW3DAssetManager::Get_Instance()->Get_FontChars( name, size, bold );
8386

8487
if( fontChar == NULL )
8588
{
86-
87-
DEBUG_LOG(( "W3D load font: unable to find font '%s' from asset manager",
88-
font->nameString.str() ));
89-
DEBUG_ASSERTCRASH(fontChar, ("Missing or Corrupted Font. Pleas see log for details"));
89+
DEBUG_CRASH(( "Unable to find font '%s' in Asset Manager", name ));
9090
return FALSE;
91-
9291
}
9392

9493
// assign font data
9594
font->fontData = fontChar;
9695
font->height = fontChar->Get_Char_Height();
9796

98-
FontCharsClass *unicodeFontChar = NULL;
99-
100-
// load unicode of same point size
101-
if(TheGlobalLanguageData)
102-
unicodeFontChar = WW3DAssetManager::
103-
Get_Instance()->Get_FontChars( TheGlobalLanguageData->m_unicodeFontName.str(), font->pointSize,
104-
font->bold ? true : false );
105-
else
106-
unicodeFontChar = WW3DAssetManager::
107-
Get_Instance()->Get_FontChars( "Arial Unicode MS", font->pointSize,
108-
font->bold ? true : false );
97+
// load Unicode of same point size
98+
name = TheGlobalLanguageData ? TheGlobalLanguageData->m_unicodeFontName.str() : "Arial Unicode MS";
99+
fontChar->AlternateUnicodeFont = WW3DAssetManager::Get_Instance()->Get_FontChars( name, size, bold );
109100

110-
if ( unicodeFontChar )
111-
{
112-
fontChar->AlternateUnicodeFont = unicodeFontChar;
113-
}
114-
115-
// all done and loaded
116101
return TRUE;
117-
118102
}
119103

120104
// W3DFontLibrary::releaseFontData ============================================

Generals/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/W3DGameWindow.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,11 +520,14 @@ void W3DGameWindow::winDrawBorder( void )
520520
}
521521

522522
// W3DGameWindow::winSetFont ==================================================
523-
/** Set the font for a widow */
523+
/** Set the font for a window */
524524
//=============================================================================
525525
void W3DGameWindow::winSetFont( GameFont *font )
526526
{
527527

528+
if (font == NULL)
529+
return;
530+
528531
// extending functionality
529532
GameWindow::winSetFont( font );
530533

Generals/Code/Libraries/Source/WWVegas/WW3D2/assetmgr.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,12 +1485,17 @@ FontCharsClass * WW3DAssetManager::Get_FontChars( const char * name, int point_s
14851485
}
14861486
}
14871487

1488-
// If one hasn't been found, create it
1488+
// If one hasn't been found, try create it
14891489
FontCharsClass * font = NEW_REF( FontCharsClass, () );
1490-
font->Initialize_GDI_Font( name, point_size, is_bold );
1491-
font->Add_Ref();
1492-
FontCharsList.Add( font ); // add it to the list
1493-
return font; // return it
1490+
if (font->Initialize_GDI_Font( name, point_size, is_bold ))
1491+
{
1492+
font->Add_Ref();
1493+
FontCharsList.Add( font );
1494+
return font;
1495+
}
1496+
1497+
font->Release_Ref();
1498+
return NULL;
14941499
}
14951500

14961501

0 commit comments

Comments
 (0)