Changeset - r27482:151ee53cd970
[Not reviewed]
master
0 1 0
Patric Stout - 18 months ago 2023-06-03 19:09:02
truebrain@openttd.org
Fix: Wayland crash on startup due to Pango also using FontConfig (#10916)

Basically, we haven't been a good neighbour. Turns out you shouldn't
actually call FcFini when you are done, as some library might still
want to use FontConfig. And they use a shared instance for their
administration.

The idea is that you call FcInit once, and use FcConfigReference
after that to get an instance, you can release. This entry is
ref-counted, and things happen automatically based on that.

At least, I think.
1 file changed with 13 insertions and 6 deletions:
0 comments (0 inline, 0 general)
src/os/unix/font_unix.cpp
Show inline comments
 
@@ -28,13 +28,18 @@ extern FT_Library _library;
 
FT_Error GetFontByFaceName(const char *font_name, FT_Face *face)
 
{
 
	FT_Error err = FT_Err_Cannot_Open_Resource;
 

	
 
	if (!FcInit()) {
 
		ShowInfo("Unable to load font configuration");
 
	} else {
 
		return err;
 
	}
 

	
 
	auto fc_instance = FcConfigReference(nullptr);
 
	assert(fc_instance != nullptr);
 

	
 
		FcPattern *match;
 
		FcPattern *pat;
 
		FcFontSet *fs;
 
		FcResult  result;
 
		char *font_style;
 
		char *font_family;
 
@@ -84,26 +89,28 @@ FT_Error GetFontByFaceName(const char *f
 
			}
 
		}
 

	
 
		free(font_family);
 
		FcPatternDestroy(pat);
 
		FcFontSetDestroy(fs);
 
		FcFini();
 
	}
 
	FcConfigDestroy(fc_instance);
 

	
 
	return err;
 
}
 

	
 
#endif /* WITH_FREETYPE */
 

	
 

	
 
bool SetFallbackFont(FontCacheSettings *settings, const char *language_isocode, int winlangid, MissingGlyphSearcher *callback)
 
{
 
	if (!FcInit()) return false;
 
	bool ret = false;
 

	
 
	bool ret = false;
 
	if (!FcInit()) return ret;
 

	
 
	auto fc_instance = FcConfigReference(nullptr);
 
	assert(fc_instance != nullptr);
 

	
 
	/* Fontconfig doesn't handle full language isocodes, only the part
 
	 * before the _ of e.g. en_GB is used, so "remove" everything after
 
	 * the _. */
 
	char lang[16];
 
	seprintf(lang, lastof(lang), ":lang=%s", language_isocode);
 
@@ -165,9 +172,9 @@ bool SetFallbackFont(FontCacheSettings *
 
		}
 

	
 
		/* Clean up the list of filenames. */
 
		FcFontSetDestroy(fs);
 
	}
 

	
 
	FcFini();
 
	FcConfigDestroy(fc_instance);
 
	return ret;
 
}
0 comments (0 inline, 0 general)