From 639b10bc1cffca0c6b3e735aa7c4a33e9eab95ad Mon Sep 17 00:00:00 2001 From: Martijn Versteegh Date: Fri, 14 Apr 2023 23:11:37 +0200 Subject: [PATCH] Make first non-anonymous CustomData layer active For each created CustomData layer check if the previous active layer was an anonymous layer and if so set the new layer as active. Do the same for the render/clone/mask layer. This way we never end up in a state where a mesh has non-anonymous layers but none of them are active. --- source/blender/blenkernel/intern/customdata.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc index c513f5edb81..f770aa88653 100644 --- a/source/blender/blenkernel/intern/customdata.cc +++ b/source/blender/blenkernel/intern/customdata.cc @@ -2851,6 +2851,24 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data, new_layer.active_rnd = data->layers[index - 1].active_rnd; new_layer.active_clone = data->layers[index - 1].active_clone; new_layer.active_mask = data->layers[index - 1].active_mask; + + /* Even though the typemap is invalidated for all types larger than the current type + * it's still valid for the current, because the layers are sorted by type. */ + int first_layer_of_type = data->typemap[type]; + /* If the previous active layer is an anonymous layer make the new one the active one. + * and analogous for the render,clone and mask layers */ + if (data->layers[first_layer_of_type + new_layer.active].anonymous_id) { + new_layer.active = index - first_layer_of_type; + } + if (data->layers[first_layer_of_type + new_layer.active_rnd].anonymous_id) { + new_layer.active_rnd = index - first_layer_of_type; + } + if (data->layers[first_layer_of_type + new_layer.active_clone].anonymous_id) { + new_layer.active_clone = index - first_layer_of_type; + } + if (data->layers[first_layer_of_type + new_layer.active_mask].anonymous_id) { + new_layer.active_mask = index - first_layer_of_type; + } } else { new_layer.active = 0; -- 2.30.2