summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <remi@verschelde.fr>2021-06-13 10:50:27 +0200
committerGitHub <noreply@github.com>2021-06-13 10:50:27 +0200
commite866a5342826d3c3e8afe0309a311d58f3b6b4d3 (patch)
tree5cf59583e446373765bd86af3267a476ddcc0fea
parent95932ce4f2938b574d57853f3e91b4e63c7d76b4 (diff)
parenta23610ad90b400297d9008b36ab86e60f173920f (diff)
Merge pull request #49559 from timothyqiu/color-index
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;
}