Fix crash when GameFont is not defined (f.e in main-menu).

This commit is contained in:
joris 2013-04-20 15:52:35 +02:00
parent e8451ddea9
commit c971512ce6
3 changed files with 18 additions and 9 deletions
src
include
ui
video

View file

@ -150,19 +150,17 @@ public:
#define FontGrey "grey"
/*----------------------------------------------------------------------------
-- Variables
-- Functions
----------------------------------------------------------------------------*/
/**
** Font selector for the font functions.
** FIXME: should be moved to lua
*/
extern CFont &GetSmallFont(); /// Small font used in stats
extern CFont &GetGameFont(); /// Normal font used in game
extern CFont &GetSmallFont(); /// Small font used in stats
extern CFont &GetGameFont(); /// Normal font used in game
extern bool IsGameFontReady(); /// true when GameFont is provided
/*----------------------------------------------------------------------------
-- Functions
----------------------------------------------------------------------------*/
/// Set the default text colors for normal and reverse text
extern void SetDefaultTextColors(const std::string &normal, const std::string &reverse);

View file

@ -85,7 +85,7 @@ void ShowLoadProgress(const char *fmt, ...)
temp[sizeof(temp) - 1] = '\0';
va_end(va);
if (Video.Depth && GetGameFont().IsLoaded()) {
if (Video.Depth && IsGameFontReady() && GetGameFont().IsLoaded()) {
// Remove non printable chars
for (char *s = temp; *s; ++s) {
if (*s < 32) {

View file

@ -84,6 +84,11 @@ CFont &GetSmallFont()
return *SmallFont;
}
bool IsGameFontReady()
{
return GameFont != NULL || CFont::Get("game") != NULL;
}
CFont &GetGameFont()
{
if (!GameFont) {
@ -978,9 +983,15 @@ void ReloadFonts()
*/
/* static */ CFont *CFont::Get(const std::string &ident)
{
CFont *font = Fonts[ident];
if (!font) {
std::map<std::string, CFont *>::iterator it = Fonts.find(ident);
if (it == Fonts.end()) {
DebugPrint("font not found: %s\n" _C_ ident.c_str());
return NULL;
}
CFont *font = it->second;
if (font == NULL) {
DebugPrint("font not found: %s\n" _C_ ident.c_str());
return NULL;
}
return font;
}