From a6b625eea3469719a6169e496199b8566657fc43 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sat, 17 Jun 2023 17:56:27 +0100 Subject: [PATCH] Fix #10993: Crash log when font caches not initialised (#11024) See also: #10836 --- src/crashlog.cpp | 8 ++++---- src/fontcache.cpp | 15 +++++++++++++++ src/fontcache.h | 2 ++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/crashlog.cpp b/src/crashlog.cpp index 8be9bc134c..f8f4677ce0 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -183,10 +183,10 @@ void CrashLog::LogConfiguration(std::back_insert_iterator &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); diff --git a/src/fontcache.cpp b/src/fontcache.cpp index dcaa05d25a..096d5eddde 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -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. diff --git a/src/fontcache.h b/src/fontcache.h index 6f9958f889..04c38a6888 100644 --- a/src/fontcache.h +++ b/src/fontcache.h @@ -147,6 +147,8 @@ public: return FontCache::caches[fs]; } + static std::string GetName(FontSize fs); + /** * Check whether the font cache has a parent. */