Cleanup: Use string argument for attribute API function

Instead of CustomDataLayer, which exposes the internal implementation
more than necessary, and requires that the layer is always available,
which isn't always true.
This commit is contained in:
Hans Goudey 2022-11-10 14:38:49 -06:00
parent 34f4646786
commit ca1642cd0c
Notes: blender-bot 2023-02-13 23:17:13 +01:00
Referenced by issue #103064, Realtime Compositor: Crash on undo after dissolve node
Referenced by issue #103063, Realtime Compositor: Crash if first enable compositor and after this create node tree
Referenced by issue #102482, GN: Crash with Shift+A when editing files containing node group assets
4 changed files with 9 additions and 24 deletions

View File

@ -90,7 +90,7 @@ int BKE_id_attributes_length(const struct ID *id,
eCustomDataMask mask);
struct CustomDataLayer *BKE_id_attributes_active_get(struct ID *id);
void BKE_id_attributes_active_set(struct ID *id, struct CustomDataLayer *layer);
void BKE_id_attributes_active_set(struct ID *id, const char *name);
int *BKE_id_attributes_active_index_p(struct ID *id);
CustomData *BKE_id_attributes_iterator_next_domain(struct ID *id, struct CustomDataLayer *layers);

View File

@ -495,29 +495,14 @@ CustomDataLayer *BKE_id_attributes_active_get(ID *id)
return nullptr;
}
void BKE_id_attributes_active_set(ID *id, CustomDataLayer *active_layer)
void BKE_id_attributes_active_set(ID *id, const char *name)
{
DomainInfo info[ATTR_DOMAIN_NUM];
get_domains(id, info);
const CustomDataLayer *layer = BKE_id_attribute_search(
id, name, CD_MASK_PROP_ALL, ATTR_DOMAIN_MASK_ALL);
BLI_assert(layer != nullptr);
int index = 0;
for (const int domain : IndexRange(ATTR_DOMAIN_NUM)) {
const CustomData *customdata = info[domain].customdata;
if (customdata == nullptr) {
continue;
}
for (int i = 0; i < customdata->totlayer; i++) {
const CustomDataLayer *layer = &customdata->layers[i];
if (layer == active_layer) {
*BKE_id_attributes_active_index_p(id) = index;
return;
}
if (CD_MASK_PROP_ALL & CD_TYPE_AS_MASK(layer->type)) {
index++;
}
}
}
const int index = BKE_id_attribute_to_index(id, layer, ATTR_DOMAIN_MASK_ALL, CD_MASK_PROP_ALL);
*BKE_id_attributes_active_index_p(id) = index;
}
int *BKE_id_attributes_active_index_p(ID *id)

View File

@ -98,7 +98,7 @@ static int geometry_attribute_add_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
BKE_id_attributes_active_set(id, layer);
BKE_id_attributes_active_set(id, layer->name);
DEG_id_tag_update(id, ID_RECALC_GEOMETRY);
WM_main_add_notifier(NC_GEOM | ND_DATA, id);

View File

@ -534,7 +534,7 @@ static void rna_AttributeGroup_active_set(PointerRNA *ptr,
{
ID *id = ptr->owner_id;
CustomDataLayer *layer = attribute_ptr.data;
BKE_id_attributes_active_set(id, layer);
BKE_id_attributes_active_set(id, layer->name);
}
static void rna_AttributeGroup_active_index_set(PointerRNA *ptr, int value)