@@ -1359,7 +1359,7 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontAdvanced *p_font_data,
13591359 return false ;
13601360}
13611361
1362- _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size (FontAdvanced *p_font_data, const Vector2i &p_size, FontForSizeAdvanced *&r_cache_for_size) const {
1362+ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size (FontAdvanced *p_font_data, const Vector2i &p_size, FontForSizeAdvanced *&r_cache_for_size, bool p_silent ) const {
13631363 ERR_FAIL_COND_V (p_size.x <= 0 , false );
13641364
13651365 HashMap<Vector2i, FontForSizeAdvanced *>::Iterator E = p_font_data->cache .find (p_size);
@@ -1380,7 +1380,11 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
13801380 error = FT_Init_FreeType (&ft_library);
13811381 if (error != 0 ) {
13821382 memdelete (fd);
1383- ERR_FAIL_V_MSG (false , " FreeType: Error initializing library: '" + String (FT_Error_String (error)) + " '." );
1383+ if (p_silent) {
1384+ return false ;
1385+ } else {
1386+ ERR_FAIL_V_MSG (false , " FreeType: Error initializing library: '" + String (FT_Error_String (error)) + " '." );
1387+ }
13841388 }
13851389#ifdef MODULE_SVG_ENABLED
13861390 FT_Property_Set (ft_library, " ot-svg" , " svg-hooks" , get_tvg_svg_in_ot_hooks ());
@@ -1414,7 +1418,11 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
14141418 FT_Done_Face (fd->face );
14151419 fd->face = nullptr ;
14161420 memdelete (fd);
1417- ERR_FAIL_V_MSG (false , " FreeType: Error loading font: '" + String (FT_Error_String (error)) + " '." );
1421+ if (p_silent) {
1422+ return false ;
1423+ } else {
1424+ ERR_FAIL_V_MSG (false , " FreeType: Error loading font: '" + String (FT_Error_String (error)) + " '." );
1425+ }
14181426 }
14191427 }
14201428
@@ -1849,7 +1857,11 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
18491857 }
18501858#else
18511859 memdelete (fd);
1852- ERR_FAIL_V_MSG (false , " FreeType: Can't load dynamic font, engine is compiled without FreeType support!" );
1860+ if (p_silent) {
1861+ return false ;
1862+ } else {
1863+ ERR_FAIL_V_MSG (false , " FreeType: Can't load dynamic font, engine is compiled without FreeType support!" );
1864+ }
18531865#endif
18541866 } else {
18551867 // Init bitmap font.
@@ -1860,6 +1872,16 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
18601872 return true ;
18611873}
18621874
1875+ _FORCE_INLINE_ bool TextServerAdvanced::_font_validate (const RID &p_font_rid) const {
1876+ FontAdvanced *fd = _get_font_data (p_font_rid);
1877+ ERR_FAIL_NULL_V (fd, false );
1878+
1879+ MutexLock lock (fd->mutex );
1880+ Vector2i size = _get_size (fd, 16 );
1881+ FontForSizeAdvanced *ffsd = nullptr ;
1882+ return _ensure_cache_for_size (fd, size, ffsd, true );
1883+ }
1884+
18631885_FORCE_INLINE_ void TextServerAdvanced::_font_clear_cache (FontAdvanced *p_font_data) {
18641886 MutexLock ftlock (ft_mutex);
18651887
@@ -5108,6 +5130,10 @@ RID TextServerAdvanced::_find_sys_font_for_text(const RID &p_fdef, const String
51085130 SystemFontCacheRec sysf;
51095131 sysf.rid = _create_font ();
51105132 _font_set_data_ptr (sysf.rid , font_data.ptr (), font_data.size ());
5133+ if (!_font_validate (sysf.rid )) {
5134+ _free_rid (sysf.rid );
5135+ continue ;
5136+ }
51115137
51125138 Dictionary var = dvar;
51135139 // Select matching style from collection.
0 commit comments