浏览代码

Suppress error messages when using ConfigFile::get_value and a default is given

Fixes #8097

(cherry picked from commit 927d15b815ff5bbc9693b98fb6ce177b84a76def)
Bojidar Marinov 8 年之前
父节点
当前提交
0afb9b579f
共有 1 个文件被更改,包括 7 次插入2 次删除
  1. 7 2
      core/io/config_file.cpp

+ 7 - 2
core/io/config_file.cpp

@@ -82,8 +82,13 @@ void ConfigFile::set_value(const String &p_section, const String &p_key, const V
 }
 Variant ConfigFile::get_value(const String &p_section, const String &p_key, Variant p_default) const {
 
-	ERR_FAIL_COND_V(!values.has(p_section), p_default);
-	ERR_FAIL_COND_V(!values[p_section].has(p_key), p_default);
+	if (!values.has(p_section) || !values[p_section].has(p_key)) {
+		if (p_default.get_type() == Variant::NIL) {
+			ERR_EXPLAIN("Couldn't find the given section/key and no default was given");
+			ERR_FAIL_V(p_default);
+		}
+		return p_default;
+	}
 	return values[p_section][p_key];
 }