Fix: improve CD_ASSIGN handling when adding custom data layer
Previously, the code would incorrectly free the passed in custom data layer even when `CD_ASSIGN` was not used. Now the function actually supports assigning the data to the layer. This only fixes the case for custom data layer types that only support a single layer like `CD_MEDGE`. Informally reviewed by Hans Goudey.
This commit is contained in:
parent
c3391d537b
commit
0a7308a0f1
Notes:
blender-bot
2023-02-14 06:05:22 +01:00
Referenced by commit ff7645c5ed
, Fix T102404: Behavior change in CustomData API
Referenced by issue #102419, Regression: Geometry nodes Missing Mesh overlays in edit mode
Referenced by issue #102419, Regression: Geometry nodes Missing Mesh overlays in edit mode
Referenced by issue #102404, Reading+Writing edge bevel weights with python api only working correctly on last element
|
@ -2799,11 +2799,6 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data,
|
|||
const LayerTypeInfo *typeInfo = layerType_getInfo(type);
|
||||
int flag = 0;
|
||||
|
||||
if (!typeInfo->defaultname && CustomData_has_layer(data, type)) {
|
||||
MEM_SAFE_FREE(layerdata);
|
||||
return &data->layers[CustomData_get_layer_index(data, type)];
|
||||
}
|
||||
|
||||
void *newlayerdata = nullptr;
|
||||
switch (alloctype) {
|
||||
case CD_SET_DEFAULT:
|
||||
|
@ -2856,6 +2851,21 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data,
|
|||
break;
|
||||
}
|
||||
|
||||
/* Some layer types only support a single layer. */
|
||||
const bool reuse_existing_layer = !typeInfo->defaultname && CustomData_has_layer(data, type);
|
||||
if (reuse_existing_layer) {
|
||||
CustomDataLayer &layer = data->layers[CustomData_get_layer_index(data, type)];
|
||||
if (layer.data != nullptr) {
|
||||
if (typeInfo->free) {
|
||||
typeInfo->free(layer.data, totelem, typeInfo->size);
|
||||
}
|
||||
MEM_SAFE_FREE(layer.data);
|
||||
}
|
||||
layer.data = newlayerdata;
|
||||
layer.flag = flag;
|
||||
return &layer;
|
||||
}
|
||||
|
||||
int index = data->totlayer;
|
||||
if (index >= data->maxlayer) {
|
||||
if (!customData_resize(data, CUSTOMDATA_GROW)) {
|
||||
|
|
Loading…
Reference in New Issue