@@ -84,11 +84,13 @@ FontEngine::~FontEngine()
84
84
/* *****************************************************************************/
85
85
void FontEngine::cleanCache ()
86
86
{
87
+ RecursiveMutexAutoLock l (m_font_mutex);
88
+
87
89
for (auto &font_cache_it : m_font_cache) {
88
90
89
91
for (auto &font_it : font_cache_it) {
90
92
font_it.second ->drop ();
91
- font_it.second = NULL ;
93
+ font_it.second = nullptr ;
92
94
}
93
95
font_cache_it.clear ();
94
96
}
@@ -122,6 +124,8 @@ irr::gui::IGUIFont *FontEngine::getFont(FontSpec spec, bool may_fail)
122
124
if (spec.size == FONT_SIZE_UNSPECIFIED)
123
125
spec.size = m_default_size[spec.mode ];
124
126
127
+ RecursiveMutexAutoLock l (m_font_mutex);
128
+
125
129
const auto &cache = m_font_cache[spec.getHash ()];
126
130
auto it = cache.find (spec.size );
127
131
if (it != cache.end ())
@@ -149,42 +153,23 @@ irr::gui::IGUIFont *FontEngine::getFont(FontSpec spec, bool may_fail)
149
153
/* *****************************************************************************/
150
154
unsigned int FontEngine::getTextHeight (const FontSpec &spec)
151
155
{
152
- irr::gui::IGUIFont *font = getFont (spec);
153
-
154
- // use current skin font as fallback
155
- if (font == NULL ) {
156
- font = m_env->getSkin ()->getFont ();
157
- }
158
- FATAL_ERROR_IF (font == NULL , " Could not get skin font" );
156
+ gui::IGUIFont *font = getFont (spec);
159
157
160
158
return font->getDimension (L" Some unimportant example String" ).Height ;
161
159
}
162
160
163
161
/* *****************************************************************************/
164
162
unsigned int FontEngine::getTextWidth (const std::wstring &text, const FontSpec &spec)
165
163
{
166
- irr::gui::IGUIFont *font = getFont (spec);
167
-
168
- // use current skin font as fallback
169
- if (font == NULL ) {
170
- font = m_env->getSkin ()->getFont ();
171
- }
172
- FATAL_ERROR_IF (font == NULL , " Could not get font" );
164
+ gui::IGUIFont *font = getFont (spec);
173
165
174
166
return font->getDimension (text.c_str ()).Width ;
175
167
}
176
168
177
-
178
169
/* * get line height for a specific font (including empty room between lines) */
179
170
unsigned int FontEngine::getLineHeight (const FontSpec &spec)
180
171
{
181
- irr::gui::IGUIFont *font = getFont (spec);
182
-
183
- // use current skin font as fallback
184
- if (font == NULL ) {
185
- font = m_env->getSkin ()->getFont ();
186
- }
187
- FATAL_ERROR_IF (font == NULL , " Could not get font" );
172
+ gui::IGUIFont *font = getFont (spec);
188
173
189
174
return font->getDimension (L" Some unimportant example String" ).Height
190
175
+ font->getKerningHeight ();
@@ -238,22 +223,9 @@ void FontEngine::readSettings()
238
223
void FontEngine::updateSkin ()
239
224
{
240
225
gui::IGUIFont *font = getFont ();
226
+ assert (font);
241
227
242
- if (font)
243
- m_env->getSkin ()->setFont (font);
244
- else
245
- errorstream << " FontEngine: Default font file: " <<
246
- " \n\t\" " << g_settings->get (" font_path" ) << " \" " <<
247
- " \n\t required for current screen configuration was not found" <<
248
- " or was invalid file format." <<
249
- " \n\t Using irrlicht default font." << std::endl;
250
-
251
- // If we did fail to create a font our own make irrlicht find a default one
252
- font = m_env->getSkin ()->getFont ();
253
- FATAL_ERROR_IF (font == NULL , " Could not create/get font" );
254
-
255
- u32 text_height = font->getDimension (L" Hello, world!" ).Height ;
256
- infostream << " FontEngine: measured text_height=" << text_height << std::endl;
228
+ m_env->getSkin ()->setFont (font);
257
229
}
258
230
259
231
/* *****************************************************************************/
0 commit comments