From 4be87e97f48533e16594b6ec73980ffb2ba12ade Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Thu, 3 Feb 2022 16:52:16 +0100 Subject: [PATCH] Fix T94435: remove anonymous attributes when applying modifier Differential Revision: https://developer.blender.org/D13994 --- source/blender/blenkernel/BKE_customdata.h | 5 +++++ source/blender/blenkernel/intern/customdata.cc | 18 ++++++++++++++++++ .../blender/editors/object/object_modifier.c | 6 ++++++ 3 files changed, 29 insertions(+) diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h index 76389b0c66f..38b43e36feb 100644 --- a/source/blender/blenkernel/BKE_customdata.h +++ b/source/blender/blenkernel/BKE_customdata.h @@ -253,6 +253,11 @@ bool CustomData_free_layer_active(struct CustomData *data, int type, int totelem */ void CustomData_free_layers(struct CustomData *data, int type, int totelem); +/** + * Free all anonymous attributes. + */ +void CustomData_free_layers_anonymous(struct CustomData *data, int totelem); + /** * Returns true if a layer with the specified type exists. */ diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index 02b50027ef9..e4c18325d76 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -2780,6 +2780,24 @@ void CustomData_free_layers(CustomData *data, int type, int totelem) } } +void CustomData_free_layers_anonymous(struct CustomData *data, int totelem) +{ + while (true) { + bool found_anonymous_layer = false; + for (int i = 0; i < data->totlayer; i++) { + const CustomDataLayer *layer = &data->layers[i]; + if (layer->anonymous_id != NULL) { + CustomData_free_layer(data, layer->type, totelem, i); + found_anonymous_layer = true; + break; + } + } + if (!found_anonymous_layer) { + break; + } + } +} + bool CustomData_has_layer(const CustomData *data, int type) { return (CustomData_get_layer_index(data, type) != -1); diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c index 71ad54383a6..4ac2a9dca62 100644 --- a/source/blender/editors/object/object_modifier.c +++ b/source/blender/editors/object/object_modifier.c @@ -763,6 +763,12 @@ static bool modifier_apply_obdata( BKE_object_material_from_eval_data(bmain, ob, &mesh_applied->id); BKE_mesh_nomain_to_mesh(mesh_applied, me, ob, &CD_MASK_MESH, true); + /* Anonymous attributes shouldn't by available on the applied geometry. */ + CustomData_free_layers_anonymous(&me->vdata, me->totvert); + CustomData_free_layers_anonymous(&me->edata, me->totedge); + CustomData_free_layers_anonymous(&me->pdata, me->totpoly); + CustomData_free_layers_anonymous(&me->ldata, me->totloop); + if (md_eval->type == eModifierType_Multires) { multires_customdata_delete(me); }