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:
parent
98c0802ab0
commit
a4051b31d5
|
@ -3755,7 +3755,7 @@ static int dash_modifier_segment_add_exec(bContext *C, wmOperator *op)
|
||||||
GreasePencilDashModifierSegment *new_segments = static_cast<GreasePencilDashModifierSegment *>(
|
GreasePencilDashModifierSegment *new_segments = static_cast<GreasePencilDashModifierSegment *>(
|
||||||
MEM_malloc_arrayN(dmd->segments_num + 1, sizeof(GreasePencilDashModifierSegment), __func__));
|
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) {
|
if (dmd->segments_num != 0) {
|
||||||
/* Copy the segments before the new segment. */
|
/* Copy the segments before the new segment. */
|
||||||
memcpy(new_segments,
|
memcpy(new_segments,
|
||||||
|
|
|
@ -888,7 +888,7 @@
|
||||||
|
|
||||||
#define _DNA_DEFAULT_GreasePencilDashModifierSegment \
|
#define _DNA_DEFAULT_GreasePencilDashModifierSegment \
|
||||||
{ \
|
{ \
|
||||||
.name = "", \
|
.name = "Segment", \
|
||||||
.dash = 2, \
|
.dash = 2, \
|
||||||
.gap = 1, \
|
.gap = 1, \
|
||||||
.radius = 1.0f, \
|
.radius = 1.0f, \
|
||||||
|
|
Loading…
Reference in New Issue