mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-11-04 01:05:48 +01:00 
			
		
		
		
	Reload font manager in main thread to avoid a crash (#15900)
This commit is contained in:
		@@ -18,10 +18,9 @@
 | 
			
		||||
/** reference to access font engine, has to be initialized by main */
 | 
			
		||||
FontEngine *g_fontengine = nullptr;
 | 
			
		||||
 | 
			
		||||
/** callback to be used on change of font size setting */
 | 
			
		||||
static void font_setting_changed(const std::string &name, void *userdata)
 | 
			
		||||
void FontEngine::fontSettingChanged(const std::string &name, void *userdata)
 | 
			
		||||
{
 | 
			
		||||
	static_cast<FontEngine *>(userdata)->readSettings();
 | 
			
		||||
	((FontEngine *)userdata)->m_needs_reload = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static const char *settings[] = {
 | 
			
		||||
@@ -49,7 +48,7 @@ FontEngine::FontEngine(gui::IGUIEnvironment* env) :
 | 
			
		||||
	readSettings();
 | 
			
		||||
 | 
			
		||||
	for (auto name : settings)
 | 
			
		||||
		g_settings->registerChangedCallback(name, font_setting_changed, this);
 | 
			
		||||
		g_settings->registerChangedCallback(name, fontSettingChanged, this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FontEngine::~FontEngine()
 | 
			
		||||
@@ -162,6 +161,15 @@ void FontEngine::readSettings()
 | 
			
		||||
	refresh();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FontEngine::handleReload()
 | 
			
		||||
{
 | 
			
		||||
	if (!m_needs_reload)
 | 
			
		||||
		return;
 | 
			
		||||
 | 
			
		||||
	m_needs_reload = false;
 | 
			
		||||
	readSettings();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FontEngine::updateSkin()
 | 
			
		||||
{
 | 
			
		||||
	gui::IGUIFont *font = getFont();
 | 
			
		||||
 
 | 
			
		||||
@@ -121,6 +121,9 @@ public:
 | 
			
		||||
	/** update internal parameters from settings */
 | 
			
		||||
	void readSettings();
 | 
			
		||||
 | 
			
		||||
	/** reload fonts if settings were changed */
 | 
			
		||||
	void handleReload();
 | 
			
		||||
 | 
			
		||||
	void setMediaFont(const std::string &name, const std::string &data);
 | 
			
		||||
 | 
			
		||||
	void clearMediaFonts();
 | 
			
		||||
@@ -142,6 +145,9 @@ private:
 | 
			
		||||
	/** refresh after fonts have been changed */
 | 
			
		||||
	void refresh();
 | 
			
		||||
 | 
			
		||||
	/** callback to be used on change of font size setting */
 | 
			
		||||
	static void fontSettingChanged(const std::string &name, void *userdata);
 | 
			
		||||
 | 
			
		||||
	/** pointer to irrlicht gui environment */
 | 
			
		||||
	gui::IGUIEnvironment* m_env = nullptr;
 | 
			
		||||
 | 
			
		||||
@@ -164,6 +170,8 @@ private:
 | 
			
		||||
	/** default font engine mode (fixed) */
 | 
			
		||||
	static const FontMode m_currentMode = FM_Standard;
 | 
			
		||||
 | 
			
		||||
	bool m_needs_reload = false;
 | 
			
		||||
 | 
			
		||||
	DISABLE_CLASS_COPY(FontEngine);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -970,6 +970,8 @@ void Game::run()
 | 
			
		||||
 | 
			
		||||
		framemarker.start();
 | 
			
		||||
 | 
			
		||||
		g_fontengine->handleReload();
 | 
			
		||||
 | 
			
		||||
		const auto current_dynamic_info = ClientDynamicInfo::getCurrent();
 | 
			
		||||
		if (!current_dynamic_info.equal(client_display_info)) {
 | 
			
		||||
			client_display_info = current_dynamic_info;
 | 
			
		||||
 
 | 
			
		||||
@@ -337,6 +337,8 @@ void GUIEngine::run()
 | 
			
		||||
		fps_control.limit(device, &dtime);
 | 
			
		||||
		framemarker.start();
 | 
			
		||||
 | 
			
		||||
		g_fontengine->handleReload();
 | 
			
		||||
 | 
			
		||||
		if (device->isWindowVisible()) {
 | 
			
		||||
			// check if we need to update the "upper left corner"-text
 | 
			
		||||
			if (text_height != g_fontengine->getTextHeight()) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user