aboutsummaryrefslogtreecommitdiff
path: root/src/client/fontengine.cpp
diff options
context:
space:
mode:
authorsfan5 <sfan5@live.de>2021-12-17 23:49:47 +0100
committersfan5 <sfan5@live.de>2021-12-18 20:38:33 +0100
commit49f7d2494ce178162a96da57315ad41f6c2796c6 (patch)
treebd49cbfdfa65bf8f1a2c9cd11147fbe79ad281af /src/client/fontengine.cpp
parentb2409b14d0682655363c1b3b3b6bafbaa7e7c1bf (diff)
downloadhax-minetest-server-49f7d2494ce178162a96da57315ad41f6c2796c6.tar.gz
hax-minetest-server-49f7d2494ce178162a96da57315ad41f6c2796c6.zip
Protect font initialization with mutex
fixes #4532
Diffstat (limited to 'src/client/fontengine.cpp')
-rw-r--r--src/client/fontengine.cpp48
1 files changed, 10 insertions, 38 deletions
diff --git a/src/client/fontengine.cpp b/src/client/fontengine.cpp
index f64315db4..35e908b0c 100644
--- a/src/client/fontengine.cpp
+++ b/src/client/fontengine.cpp
@@ -84,11 +84,13 @@ FontEngine::~FontEngine()
/******************************************************************************/
void FontEngine::cleanCache()
{
+ RecursiveMutexAutoLock l(m_font_mutex);
+
for (auto &font_cache_it : m_font_cache) {
for (auto &font_it : font_cache_it) {
font_it.second->drop();
- font_it.second = NULL;
+ font_it.second = nullptr;
}
font_cache_it.clear();
}
@@ -122,6 +124,8 @@ irr::gui::IGUIFont *FontEngine::getFont(FontSpec spec, bool may_fail)
if (spec.size == FONT_SIZE_UNSPECIFIED)
spec.size = m_default_size[spec.mode];
+ RecursiveMutexAutoLock l(m_font_mutex);
+
const auto &cache = m_font_cache[spec.getHash()];
auto it = cache.find(spec.size);
if (it != cache.end())
@@ -149,13 +153,7 @@ irr::gui::IGUIFont *FontEngine::getFont(FontSpec spec, bool may_fail)
/******************************************************************************/
unsigned int FontEngine::getTextHeight(const FontSpec &spec)
{
- irr::gui::IGUIFont *font = getFont(spec);
-
- // use current skin font as fallback
- if (font == NULL) {
- font = m_env->getSkin()->getFont();
- }
- FATAL_ERROR_IF(font == NULL, "Could not get skin font");
+ gui::IGUIFont *font = getFont(spec);
return font->getDimension(L"Some unimportant example String").Height;
}
@@ -163,28 +161,15 @@ unsigned int FontEngine::getTextHeight(const FontSpec &spec)
/******************************************************************************/
unsigned int FontEngine::getTextWidth(const std::wstring &text, const FontSpec &spec)
{
- irr::gui::IGUIFont *font = getFont(spec);
-
- // use current skin font as fallback
- if (font == NULL) {
- font = m_env->getSkin()->getFont();
- }
- FATAL_ERROR_IF(font == NULL, "Could not get font");
+ gui::IGUIFont *font = getFont(spec);
return font->getDimension(text.c_str()).Width;
}
-
/** get line height for a specific font (including empty room between lines) */
unsigned int FontEngine::getLineHeight(const FontSpec &spec)
{
- irr::gui::IGUIFont *font = getFont(spec);
-
- // use current skin font as fallback
- if (font == NULL) {
- font = m_env->getSkin()->getFont();
- }
- FATAL_ERROR_IF(font == NULL, "Could not get font");
+ gui::IGUIFont *font = getFont(spec);
return font->getDimension(L"Some unimportant example String").Height
+ font->getKerningHeight();
@@ -238,22 +223,9 @@ void FontEngine::readSettings()
void FontEngine::updateSkin()
{
gui::IGUIFont *font = getFont();
+ assert(font);
- if (font)
- m_env->getSkin()->setFont(font);
- else
- errorstream << "FontEngine: Default font file: " <<
- "\n\t\"" << g_settings->get("font_path") << "\"" <<
- "\n\trequired for current screen configuration was not found" <<
- " or was invalid file format." <<
- "\n\tUsing irrlicht default font." << std::endl;
-
- // If we did fail to create a font our own make irrlicht find a default one
- font = m_env->getSkin()->getFont();
- FATAL_ERROR_IF(font == NULL, "Could not create/get font");
-
- u32 text_height = font->getDimension(L"Hello, world!").Height;
- infostream << "FontEngine: measured text_height=" << text_height << std::endl;
+ m_env->getSkin()->setFont(font);
}
/******************************************************************************/