Skip to content

Commit

Permalink
Fix OpenTTD#10993: Crash log when font caches not initialised (OpenTT…
Browse files Browse the repository at this point in the history
  • Loading branch information
JGRennison authored and shoter committed Jul 16, 2023
1 parent 7cf44a2 commit fc5513c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/crashlog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ void CrashLog::LogConfiguration(std::back_insert_iterator<std::string> &output_i
" Medium: {}\n"
" Large: {}\n"
" Mono: {}\n\n",
FontCache::Get(FS_SMALL)->GetFontName(),
FontCache::Get(FS_NORMAL)->GetFontName(),
FontCache::Get(FS_LARGE)->GetFontName(),
FontCache::Get(FS_MONO)->GetFontName()
FontCache::GetName(FS_SMALL),
FontCache::GetName(FS_NORMAL),
FontCache::GetName(FS_LARGE),
FontCache::GetName(FS_MONO)
);

fmt::format_to(output_iterator, "AI Configuration (local: {}) (current: {}):\n", _local_company, _current_company);
Expand Down
15 changes: 15 additions & 0 deletions src/fontcache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,21 @@ int FontCache::GetDefaultFontHeight(FontSize fs)
return _default_font_height[fs];
}

/**
* Get the font name of a given font size.
* @param fs The font size to look up.
* @return The font name.
*/
std::string FontCache::GetName(FontSize fs)
{
FontCache *fc = FontCache::Get(fs);
if (fc != nullptr) {
return fc->GetFontName();
} else {
return "[NULL]";
}
}


/**
* Get height of a character for a given font size.
Expand Down
2 changes: 2 additions & 0 deletions src/fontcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ class FontCache {
return FontCache::caches[fs];
}

static std::string GetName(FontSize fs);

/**
* Check whether the font cache has a parent.
*/
Expand Down

0 comments on commit fc5513c

Please sign in to comment.