Skip to content

Commit 581f97c

Browse files
committed
Validate name in add_blend_point and forbid duplicates
Name validation is already done in `set_blend_point_name` so it should be done in `add_blend_point` as well.
1 parent a864370 commit 581f97c

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

scene/animation/animation_blend_space_1d.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ void AnimationNodeBlendSpace1D::add_blend_point(const Ref<AnimationRootNode> &p_
166166
#else
167167
ERR_FAIL_COND(p_name == StringName());
168168
#endif
169+
ERR_FAIL_COND(p_name.is_empty() || String(p_name).contains_char('.') || String(p_name).contains_char('/'));
170+
ERR_FAIL_COND_MSG(find_blend_point_by_name(p_name) != -1, "Blend point name must be unique.");
169171
if (p_at_index == -1 || p_at_index == blend_points_used) {
170172
p_at_index = blend_points_used;
171173
} else {
@@ -220,6 +222,8 @@ void AnimationNodeBlendSpace1D::set_blend_point_name(int p_point, const StringNa
220222
ERR_FAIL_INDEX(p_point, blend_points_used);
221223
String new_name = p_name;
222224
ERR_FAIL_COND(new_name.is_empty() || new_name.contains_char('.') || new_name.contains_char('/'));
225+
int existing_index = find_blend_point_by_name(p_name);
226+
ERR_FAIL_COND_MSG(existing_index != -1 && existing_index != p_point, "Blend point name must be unique.");
223227

224228
String old_name = blend_points[p_point].name;
225229
if (new_name != old_name) {

scene/animation/animation_blend_space_2d.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_
7878
ERR_FAIL_COND(p_name == StringName());
7979
#endif
8080

81+
ERR_FAIL_COND(p_name.is_empty() || String(p_name).contains_char('.') || String(p_name).contains_char('/'));
82+
ERR_FAIL_COND_MSG(find_blend_point_by_name(p_name) != -1, "Blend point name must be unique.");
8183
if (p_at_index == -1 || p_at_index == blend_points_used) {
8284
p_at_index = blend_points_used;
8385
} else {
@@ -139,6 +141,8 @@ void AnimationNodeBlendSpace2D::set_blend_point_name(int p_point, const StringNa
139141
ERR_FAIL_INDEX(p_point, blend_points_used);
140142
String new_name = p_name;
141143
ERR_FAIL_COND(new_name.is_empty() || new_name.contains_char('.') || new_name.contains_char('/'));
144+
int existing_index = find_blend_point_by_name(p_name);
145+
ERR_FAIL_COND_MSG(existing_index != -1 && existing_index != p_point, "Blend point name must be unique.");
142146

143147
String old_name = blend_points[p_point].name;
144148
if (new_name != old_name) {

0 commit comments

Comments
 (0)