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