@@ -1357,7 +1357,7 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_glyph(FontAdvanced *p_font_data,
13571357 return false ;
13581358}
13591359
1360- _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size (FontAdvanced *p_font_data, const Vector2i &p_size, FontForSizeAdvanced *&r_cache_for_size) const {
1360+ _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 {
13611361 ERR_FAIL_COND_V (p_size.x <= 0 , false );
13621362
13631363 HashMap<Vector2i, FontForSizeAdvanced *>::Iterator E = p_font_data->cache .find (p_size);
@@ -1378,7 +1378,11 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
13781378 error = FT_Init_FreeType (&ft_library);
13791379 if (error != 0 ) {
13801380 memdelete (fd);
1381- ERR_FAIL_V_MSG (false , " FreeType: Error initializing library: '" + String (FT_Error_String (error)) + " '." );
1381+ if (p_silent) {
1382+ return false ;
1383+ } else {
1384+ ERR_FAIL_V_MSG (false , " FreeType: Error initializing library: '" + String (FT_Error_String (error)) + " '." );
1385+ }
13821386 }
13831387#ifdef MODULE_SVG_ENABLED
13841388 FT_Property_Set (ft_library, " ot-svg" , " svg-hooks" , get_tvg_svg_in_ot_hooks ());
@@ -1412,7 +1416,11 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
14121416 FT_Done_Face (fd->face );
14131417 fd->face = nullptr ;
14141418 memdelete (fd);
1415- ERR_FAIL_V_MSG (false , " FreeType: Error loading font: '" + String (FT_Error_String (error)) + " '." );
1419+ if (p_silent) {
1420+ return false ;
1421+ } else {
1422+ ERR_FAIL_V_MSG (false , " FreeType: Error loading font: '" + String (FT_Error_String (error)) + " '." );
1423+ }
14161424 }
14171425 }
14181426
@@ -1847,7 +1855,11 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
18471855 }
18481856#else
18491857 memdelete (fd);
1850- ERR_FAIL_V_MSG (false , " FreeType: Can't load dynamic font, engine is compiled without FreeType support!" );
1858+ if (p_silent) {
1859+ return false ;
1860+ } else {
1861+ ERR_FAIL_V_MSG (false , " FreeType: Can't load dynamic font, engine is compiled without FreeType support!" );
1862+ }
18511863#endif
18521864 } else {
18531865 // Init bitmap font.
@@ -1858,6 +1870,16 @@ _FORCE_INLINE_ bool TextServerAdvanced::_ensure_cache_for_size(FontAdvanced *p_f
18581870 return true ;
18591871}
18601872
1873+ _FORCE_INLINE_ bool TextServerAdvanced::_font_validate (const RID &p_font_rid) const {
1874+ FontAdvanced *fd = _get_font_data (p_font_rid);
1875+ ERR_FAIL_NULL_V (fd, false );
1876+
1877+ MutexLock lock (fd->mutex );
1878+ Vector2i size = _get_size (fd, 16 );
1879+ FontForSizeAdvanced *ffsd = nullptr ;
1880+ return _ensure_cache_for_size (fd, size, ffsd, true );
1881+ }
1882+
18611883_FORCE_INLINE_ void TextServerAdvanced::_font_clear_cache (FontAdvanced *p_font_data) {
18621884 MutexLock ftlock (ft_mutex);
18631885
@@ -5106,6 +5128,10 @@ RID TextServerAdvanced::_find_sys_font_for_text(const RID &p_fdef, const String
51065128 SystemFontCacheRec sysf;
51075129 sysf.rid = _create_font ();
51085130 _font_set_data_ptr (sysf.rid , font_data.ptr (), font_data.size ());
5131+ if (!_font_validate (sysf.rid )) {
5132+ _free_rid (sysf.rid );
5133+ continue ;
5134+ }
51095135
51105136 Dictionary var = dvar;
51115137 // Select matching style from collection.
0 commit comments