diff --git a/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc b/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc index d31741c1011..3ae643fabfc 100644 --- a/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc +++ b/source/blender/blenkernel/intern/grease_pencil_convert_legacy.cc @@ -637,11 +637,11 @@ class AnimDataConvertor { * - Array of indices in the new vertex group list for remapping */ static void find_used_vertex_groups(const bGPDframe &gpf, - const ListBase &all_names, + const ListBase &vertex_group_names, + const int num_vertex_groups, ListBase &r_vertex_group_names, Array &r_indices) { - const int num_vertex_groups = BLI_listbase_count(&all_names); Array is_group_used(num_vertex_groups, false); LISTBASE_FOREACH (bGPDstroke *, gps, &gpf.strokes) { if (!gps->dvert) { @@ -650,7 +650,7 @@ static void find_used_vertex_groups(const bGPDframe &gpf, Span dverts = {gps->dvert, gps->totpoints}; for (const MDeformVert &dvert : dverts) { for (const MDeformWeight &weight : Span{dvert.dw, dvert.totweight}) { - if (weight.def_nr >= dvert.totweight) { + if (weight.def_nr >= num_vertex_groups) { /* Ignore invalid deform weight group indices. */ continue; } @@ -662,7 +662,7 @@ static void find_used_vertex_groups(const bGPDframe &gpf, r_indices.reinitialize(num_vertex_groups); int new_group_i = 0; int old_group_i; - LISTBASE_FOREACH_INDEX (const bDeformGroup *, def_group, &all_names, old_group_i) { + LISTBASE_FOREACH_INDEX (const bDeformGroup *, def_group, &vertex_group_names, old_group_i) { if (!is_group_used[old_group_i]) { r_indices[old_group_i] = -1; continue; @@ -842,7 +842,9 @@ static Drawing legacy_gpencil_frame_to_grease_pencil_drawing(const bGPDframe &gp /* Find used vertex groups in this drawing. */ ListBase stroke_vertex_group_names; Array stroke_def_nr_map; - find_used_vertex_groups(gpf, vertex_group_names, stroke_vertex_group_names, stroke_def_nr_map); + const int num_vertex_groups = BLI_listbase_count(&vertex_group_names); + find_used_vertex_groups( + gpf, vertex_group_names, num_vertex_groups, stroke_vertex_group_names, stroke_def_nr_map); BLI_assert(BLI_listbase_is_empty(&curves.vertex_group_names)); curves.vertex_group_names = stroke_vertex_group_names; const bool use_dverts = !BLI_listbase_is_empty(&curves.vertex_group_names); @@ -853,7 +855,7 @@ static Drawing legacy_gpencil_frame_to_grease_pencil_drawing(const bGPDframe &gp dst_dvert.dw = static_cast(MEM_dupallocN(src_dvert.dw)); const MutableSpan vertex_weights = {dst_dvert.dw, dst_dvert.totweight}; for (MDeformWeight &weight : vertex_weights) { - if (weight.def_nr >= dst_dvert.totweight) { + if (weight.def_nr >= num_vertex_groups) { /* Ignore invalid deform weight group indices. */ continue; }