summaryrefslogtreecommitdiff
path: root/src/settings.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/settings.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/settings.cpp')
-rw-r--r--src/settings.cpp43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/settings.cpp b/src/settings.cpp
index b4083264e..61f35e911 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -362,6 +362,18 @@ const SettingsEntry &Settings::getEntry(const std::string &name) const
}
+const SettingsEntry &Settings::getEntryDefault(const std::string &name) const
+{
+ MutexAutoLock lock(m_mutex);
+
+ SettingEntries::const_iterator n;
+ if ((n = m_defaults.find(name)) == m_defaults.end()) {
+ throw SettingNotFoundException("Setting [" + name + "] not found.");
+ }
+ return n->second;
+}
+
+
Settings *Settings::getGroup(const std::string &name) const
{
const SettingsEntry &entry = getEntry(name);
@@ -380,6 +392,15 @@ const std::string &Settings::get(const std::string &name) const
}
+const std::string &Settings::getDefault(const std::string &name) const
+{
+ const SettingsEntry &entry = getEntryDefault(name);
+ if (entry.is_group)
+ throw SettingNotFoundException("Setting [" + name + "] is a group.");
+ return entry.value;
+}
+
+
bool Settings::getBool(const std::string &name) const
{
return is_yes(get(name));
@@ -568,6 +589,17 @@ bool Settings::getEntryNoEx(const std::string &name, SettingsEntry &val) const
}
+bool Settings::getEntryDefaultNoEx(const std::string &name, SettingsEntry &val) const
+{
+ try {
+ val = getEntryDefault(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+}
+
+
bool Settings::getGroupNoEx(const std::string &name, Settings *&val) const
{
try {
@@ -590,6 +622,17 @@ bool Settings::getNoEx(const std::string &name, std::string &val) const
}
+bool Settings::getDefaultNoEx(const std::string &name, std::string &val) const
+{
+ try {
+ val = getDefault(name);
+ return true;
+ } catch (SettingNotFoundException &e) {
+ return false;
+ }
+}
+
+
bool Settings::getFlag(const std::string &name) const
{
try {