From 1aaf18212eef02987c777663421ec18f74a97289 Mon Sep 17 00:00:00 2001 From: Binrui Dong Date: Wed, 6 Oct 2021 12:10:57 +0800 Subject: [PATCH 1/2] Verify font can be rendered successfully at runtime --- src/sdl_font.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/sdl_font.cpp b/src/sdl_font.cpp index 82c7cf03a998b..fee650114c143 100644 --- a/src/sdl_font.cpp +++ b/src/sdl_font.cpp @@ -333,7 +333,20 @@ SDL_Texture_Ptr CachedTTFFont::create_glyph( const SDL_Renderer_Ptr &renderer, bool CachedTTFFont::isGlyphProvided( const std::string &ch ) const { - return TTF_GlyphIsProvided( font.get(), UTF8_getch( ch ) ); + // Just return false if the glyph is not provided by the font + if( !TTF_GlyphIsProvided( font.get(), UTF8_getch( ch ) ) ) { + return false; + } + + // Test whether the glyph can actually be rendered + constexpr SDL_Color white{255, 255, 255, 0}; + SDL_Surface_Ptr surface( TTF_RenderUTF8_Solid( font.get(), ch.c_str(), white ) ); + if( !surface ) { + return false; + } + + // Confident that the glyph is provided by the font, and also can be rendered successfully + return true; } void CachedTTFFont::OutputChar( const SDL_Renderer_Ptr &renderer, const GeometryRenderer_Ptr &, From 712d404c415497948483fabfb4bdcd954fbd979d Mon Sep 17 00:00:00 2001 From: Binrui Dong Date: Wed, 6 Oct 2021 14:59:16 +0800 Subject: [PATCH 2/2] Fix clang-tidy warning --- src/sdl_font.cpp | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/sdl_font.cpp b/src/sdl_font.cpp index fee650114c143..1d29d95b5dfaf 100644 --- a/src/sdl_font.cpp +++ b/src/sdl_font.cpp @@ -341,12 +341,7 @@ bool CachedTTFFont::isGlyphProvided( const std::string &ch ) const // Test whether the glyph can actually be rendered constexpr SDL_Color white{255, 255, 255, 0}; SDL_Surface_Ptr surface( TTF_RenderUTF8_Solid( font.get(), ch.c_str(), white ) ); - if( !surface ) { - return false; - } - - // Confident that the glyph is provided by the font, and also can be rendered successfully - return true; + return static_cast( surface ); } void CachedTTFFont::OutputChar( const SDL_Renderer_Ptr &renderer, const GeometryRenderer_Ptr &,