summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaoyu Qiu <timothyqiu32@gmail.com>2021-06-13 14:29:32 +0800
committerHaoyu Qiu <timothyqiu32@gmail.com>2021-06-13 14:29:32 +0800
commita23610ad90b400297d9008b36ab86e60f173920f (patch)
treec630530f3c55123c6f366c161c0d4c962dd7e19c
parentccaefbce551fe6c1a0016b2f0407b6323ab8c601 (diff)
Fix crash when using invalid index in Color.get_named_color
-rw-r--r--core/math/color.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/core/math/color.cpp b/core/math/color.cpp
index 52f029ef4b..4ef47728a9 100644
--- a/core/math/color.cpp
+++ b/core/math/color.cpp
@@ -368,7 +368,7 @@ Color Color::named(const String &p_name) {
ERR_FAIL_V_MSG(Color(), "Invalid color name: " + p_name + ".");
return Color();
}
- return get_named_color(idx);
+ return named_colors[idx].color;
}
Color Color::named(const String &p_name, const Color &p_default) {
@@ -376,7 +376,7 @@ Color Color::named(const String &p_name, const Color &p_default) {
if (idx == -1) {
return p_default;
}
- return get_named_color(idx);
+ return named_colors[idx].color;
}
int Color::find_named_color(const String &p_name) {
@@ -409,10 +409,12 @@ int Color::get_named_color_count() {
}
String Color::get_named_color_name(int p_idx) {
+ ERR_FAIL_INDEX_V(p_idx, get_named_color_count(), "");
return named_colors[p_idx].name;
}
Color Color::get_named_color(int p_idx) {
+ ERR_FAIL_INDEX_V(p_idx, get_named_color_count(), Color());
return named_colors[p_idx].color;
}