diff options
author | Muhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com> | 2017-06-03 09:51:48 +0700 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2017-11-08 16:14:00 +0100 |
commit | 9526c686997285700f500b975a9d971c3ca0a188 (patch) | |
tree | 8c087577df526307b09982315dfac6d7e2fc40ee /src/settings.cpp | |
parent | d693f95fc3c9b2d487283fc16dc8988c61a94803 (diff) | |
download | minetest-9526c686997285700f500b975a9d971c3ca0a188.tar.gz minetest-9526c686997285700f500b975a9d971c3ca0a188.tar.bz2 minetest-9526c686997285700f500b975a9d971c3ca0a188.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.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/settings.cpp b/src/settings.cpp index ea54ab348..0c34eb10c 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -361,6 +361,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); @@ -379,6 +391,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)); @@ -571,6 +592,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 { @@ -593,6 +625,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 { |