diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 699f179cac2..a68f8ac4f26 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -430,6 +430,12 @@ void CustomData_swap_corners(struct CustomData *data, int index, const int *corn */ void CustomData_swap(struct CustomData *data, int index_a, int index_b, const int totelem); +/** + * Custom data layers can be shared through implicit sharing (`BLI_implicit_sharing.h`). This + * function makes sure that the layer is unshared if it was shared, which makes it mutable. + */ +void CustomData_ensure_data_is_mutable(struct CustomDataLayer *layer, int totelem); + /** * Retrieve a pointer to an element of the active layer of the given \a type, chosen by the * \a index, if it exists. diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 1cb74e8b65f..b353a179907 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -2422,6 +2422,11 @@ static void ensure_layer_data_is_mutable(CustomDataLayer &layer, const int totel } } +void CustomData_ensure_data_is_mutable(CustomDataLayer *layer, const int totelem) +{ + ensure_layer_data_is_mutable(*layer, totelem); +} + void CustomData_realloc(CustomData *data, const int old_size, const int new_size) { BLI_assert(new_size >= 0); diff --git a/source/blender/makesrna/intern/rna_attribute.c b/source/blender/makesrna/intern/rna_attribute.c index dc33a1d3fac..99d0aeafe7b 100644 --- a/source/blender/makesrna/intern/rna_attribute.c +++ b/source/blender/makesrna/intern/rna_attribute.c @@ -305,6 +305,7 @@ static void rna_Attribute_data_begin(CollectionPropertyIterator *iter, PointerRN break; } + CustomData_ensure_data_is_mutable(layer, length); rna_iterator_array_begin(iter, layer->data, struct_size, length, 0, NULL); }