[Bf-blender-cvs] [0a7308a0f14] blender-v3.4-release: Fix: improve CD_ASSIGN handling when adding custom data layer
Jacques Lucke
noreply at git.blender.org
Tue Nov 8 16:26:58 CET 2022
Commit: 0a7308a0f1493a5b0d8ab7b764893f1772ab1008
Author: Jacques Lucke
Date: Tue Nov 8 16:25:49 2022 +0100
Branches: blender-v3.4-release
https://developer.blender.org/rB0a7308a0f1493a5b0d8ab7b764893f1772ab1008
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.
===================================================================
M source/blender/blenkernel/intern/customdata.cc
===================================================================
diff --git a/source/blender/blenkernel/intern/customdata.cc b/source/blender/blenkernel/intern/customdata.cc
index e4405abdde8..01017466764 100644
--- a/source/blender/blenkernel/intern/customdata.cc
+++ b/source/blender/blenkernel/intern/customdata.cc
@@ -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)) {
More information about the Bf-blender-cvs
mailing list