Fix #118135: Make sure the new active index is always valid

When deleting all the segments the active index is generally 0. Adding a
new segment increments the active index, which pushes it out of range.
The code should not expect active index to be inside the current range.

Pull Request: https://projects.blender.org/blender/blender/pulls/118143
This commit is contained in:
Lukas Tönne 2024-02-12 16:44:28 +01:00
parent 98c0802ab0
commit a4051b31d5
2 changed files with 2 additions and 2 deletions

View File

@ -3755,7 +3755,7 @@ static int dash_modifier_segment_add_exec(bContext *C, wmOperator *op)
GreasePencilDashModifierSegment *new_segments = static_cast<GreasePencilDashModifierSegment *>(
MEM_malloc_arrayN(dmd->segments_num + 1, sizeof(GreasePencilDashModifierSegment), __func__));
const int new_active_index = dmd->segment_active_index + 1;
const int new_active_index = std::clamp(dmd->segment_active_index + 1, 0, dmd->segments_num);
if (dmd->segments_num != 0) {
/* Copy the segments before the new segment. */
memcpy(new_segments,

View File

@ -888,7 +888,7 @@
#define _DNA_DEFAULT_GreasePencilDashModifierSegment \
{ \
.name = "", \
.name = "Segment", \
.dash = 2, \
.gap = 1, \
.radius = 1.0f, \