summaryrefslogtreecommitdiff
path: root/src/fontengine.cpp
diff options
context:
space:
mode:
authorMuhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com>2017-06-03 09:51:48 +0700
committerSmallJoker <mk939@ymail.com>2018-06-03 17:32:00 +0200
commit313ca53b368abf376d3207b32fb9c8fd4291965f (patch)
tree1243fdc37f2804233f75a1e87d04375d533b8638 /src/fontengine.cpp
parenta65a46b8891255011e0f0b19490fcb7cf306f076 (diff)
downloadminetest-313ca53b368abf376d3207b32fb9c8fd4291965f.tar.gz
minetest-313ca53b368abf376d3207b32fb9c8fd4291965f.tar.bz2
minetest-313ca53b368abf376d3207b32fb9c8fd4291965f.zip
Fix issue Minetest crash when custom font path is not exist
We try to use default fallback for both mono and main font when custom font path is not exist. This way, if Minetest is not corrupted, we could avoid crash.
Diffstat (limited to 'src/fontengine.cpp')
-rw-r--r--src/fontengine.cpp68
1 files changed, 53 insertions, 15 deletions
diff --git a/src/fontengine.cpp b/src/fontengine.cpp
index da327c3f6..8eaf53c9f 100644
--- a/src/fontengine.cpp
+++ b/src/fontengine.cpp
@@ -341,32 +341,70 @@ void FontEngine::initFont(unsigned int basesize, FontMode mode)
font_path.c_str(), size, true, true, font_shadow,
font_shadow_alpha);
- if (font != NULL) {
+ if (font) {
m_font_cache[mode][basesize] = font;
return;
}
- // try fallback font
- errorstream << "FontEngine: failed to load: " << font_path << ", trying to fall back "
- "to fallback font" << std::endl;
+ if (font_config_prefix == "mono_") {
+ const std::string &mono_font_path = m_settings->getDefault("mono_font_path");
- font_path = g_settings->get(font_config_prefix + "fallback_font_path");
+ if (font_path != mono_font_path) {
+ // try original mono font
+ errorstream << "FontEngine: failed to load custom mono "
+ "font: " << font_path << ", trying to fall back to "
+ "original mono font" << std::endl;
- font = gui::CGUITTFont::createTTFont(m_env,
- font_path.c_str(), size, true, true, font_shadow,
- font_shadow_alpha);
+ font = gui::CGUITTFont::createTTFont(m_env,
+ mono_font_path.c_str(), size, true, true,
+ font_shadow, font_shadow_alpha);
- if (font != NULL) {
- m_font_cache[mode][basesize] = font;
- return;
+ if (font) {
+ m_font_cache[mode][basesize] = font;
+ return;
+ }
+ }
+ } else {
+ // 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) {
+ m_font_cache[mode][basesize] = font;
+ return;
+ }
+
+ const std::string &fallback_font_path = m_settings->getDefault("fallback_font_path");
+
+ if (font_path != fallback_font_path) {
+ // try original fallback font
+ errorstream << "FontEngine: failed to load custom fallback "
+ "font: " << font_path << ", trying to fall back to "
+ "original fallback font" << std::endl;
+
+ font = gui::CGUITTFont::createTTFont(m_env,
+ fallback_font_path.c_str(), size, true, true,
+ font_shadow, font_shadow_alpha);
+
+ if (font) {
+ 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;
+ 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
@@ -468,7 +506,7 @@ void FontEngine::initSimpleFont(unsigned int basesize, FontMode mode)
}
}
- if (font != NULL) {
+ if (font) {
font->grab();
m_font_cache[mode][basesize] = font;
}