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
 
@@ -31,7 +31,12 @@ FT_Error GetFontByFaceName(const char *f
 

	
 
	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;
 
@@ -87,8 +92,7 @@ FT_Error GetFontByFaceName(const char *f
 
		free(font_family);
 
		FcPatternDestroy(pat);
 
		FcFontSetDestroy(fs);
 
		FcFini();
 
	}
 
	FcConfigDestroy(fc_instance);
 

	
 
	return err;
 
}
 
@@ -98,9 +102,12 @@ FT_Error GetFontByFaceName(const char *f
 

	
 
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
 
@@ -168,6 +175,6 @@ bool SetFallbackFont(FontCacheSettings *
 
		FcFontSetDestroy(fs);
 
	}
 

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