Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-11-11 18:07:54 +0300
committerHans Goudey <h.goudey@me.com>2022-11-11 18:07:54 +0300
commitff7645c5edd211c5317b5fd9e6d0320c20667a21 (patch)
tree4bd40797a8e09a09035381ffde43055f6ff75453
parente508de041712cc31588cbc8d63f81970eedf3be0 (diff)
Fix T102404: Behavior change in CustomData API
Previously the `CustomData_add_layer` function always returned the existing layer data when used for types that can only have one layer. This made it work like an "ensure layer exists" function for those types. That was used in various places to make code more concise. 0a7308a0f149 changed that to always "recreate" the layer even when it existed. Maybe this is more logical for an "add layer" function, but that's not clear, and it breaks a bunch of existing code that relied on the current behavior. Rather than spending a bunch of time going through uses of the CustomData API, this patch resets the behavior to what it was before, but adds an assert and a comment to help avoid memory leaks and other issues. We should focus on moving to the attribute API instead. Differential Revision: https://developer.blender.org/D16458
-rw-r--r--source/blender/blenkernel/intern/customdata.cc23
1 files changed, 8 insertions, 15 deletions
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index 01017466764..15d92614c42 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -2799,6 +2799,14 @@ static CustomDataLayer *customData_add_layer__internal(CustomData *data,
const LayerTypeInfo *typeInfo = layerType_getInfo(type);
int flag = 0;
+ /* Some layer types only support a single layer. */
+ if (!typeInfo->defaultname && CustomData_has_layer(data, type)) {
+ /* This function doesn't support dealing with existing layer data for these layer types when
+ * the layer already exists. */
+ BLI_assert(layerdata == nullptr);
+ return &data->layers[CustomData_get_layer_index(data, type)];
+ }
+
void *newlayerdata = nullptr;
switch (alloctype) {
case CD_SET_DEFAULT:
@@ -2851,21 +2859,6 @@ 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)) {