Fix a memleak pointed by @Zeno- in MeshUpdateQueue
[oweals/minetest.git] / src / fontengine.cpp
index f881701e0f2306a2d6786772cd15ebbadf40d7fe..da327c3f603cc93ffc3398db79591e866d82a0ca 100644 (file)
@@ -122,7 +122,7 @@ void FontEngine::cleanCache()
 
                for (std::map<unsigned int, irr::gui::IGUIFont*>::iterator iter
                                = m_font_cache[i].begin();
-                               iter != m_font_cache[i].end(); iter++) {
+                               iter != m_font_cache[i].end(); ++iter) {
                        iter->second->drop();
                        iter->second = NULL;
                }
@@ -343,11 +343,31 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
 
                if (font != NULL) {
                        m_font_cache[mode][basesize] = font;
+                       return;
                }
-               else {
-                       errorstream << "FontEngine: failed to load freetype font: "
-                                       << font_path << std::endl;
+
+               // try fallback font
+               errorstream << "FontEngine: failed to load: " << font_path << ", trying to fall back "
+                               "to fallback font" << std::endl;
+
+               font_path = g_settings->get(font_config_prefix + "fallback_font_path");
+
+               font = gui::CGUITTFont::createTTFont(m_env,
+                       font_path.c_str(), size, true, true, font_shadow,
+                       font_shadow_alpha);
+
+               if (font != NULL) {
+                       m_font_cache[mode][basesize] = font;
+                       return;
                }
+
+               // give up
+               errorstream << "FontEngine: failed to load freetype font: "
+                               << font_path << std::endl;
+               errorstream << "minetest can not continue without a valid font. Please correct "
+                               "the 'font_path' setting or install the font file in the proper "
+                               "location" << std::endl;
+               abort();
        }
 #endif
 }