[Bf-blender-cvs] [ac66fb193f8] master: Fix freeing all custom-data layers

Campbell Barton noreply at git.blender.org
Fri May 26 15:25:55 CEST 2017


Commit: ac66fb193f80847fd4fc1b46413ebb3199ebbf1b
Author: Campbell Barton
Date:   Fri May 26 23:19:33 2017 +1000
Branches: master
https://developer.blender.org/rBac66fb193f80847fd4fc1b46413ebb3199ebbf1b

Fix freeing all custom-data layers

Would crash when the active index was out of range,
since there is no reason to use the active layer when freeing all,
free the first instead.

===================================================================

M	source/blender/blenkernel/intern/customdata.c

===================================================================

diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 7c3f0ac630d..331714301d5 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1944,11 +1944,16 @@ void *CustomData_add_layer_named(CustomData *data, int type, int alloctype,
 
 bool CustomData_free_layer(CustomData *data, int type, int totelem, int index)
 {
-	const int n = index - CustomData_get_layer_index(data, type);
-	int i;
-	
-	if (index < 0)
+	if (index < 0) {
+		return false;
+	}
+	const int index_first = CustomData_get_layer_index(data, type);
+	if (index_first == -1) {
 		return false;
+	}
+
+	const int n = index - index_first;
+	int i;
 
 	customData_free_layer__internal(&data->layers[index], totelem);
 
@@ -1993,8 +1998,10 @@ bool CustomData_free_layer_active(CustomData *data, int type, int totelem)
 
 void CustomData_free_layers(CustomData *data, int type, int totelem)
 {
-	while (CustomData_has_layer(data, type))
-		CustomData_free_layer_active(data, type, totelem);
+	const int index = CustomData_get_layer_index(data, type);
+	while (CustomData_free_layer(data, type, totelem, index)) {
+		/* pass */
+	}
 }
 
 bool CustomData_has_layer(const CustomData *data, int type)




More information about the Bf-blender-cvs mailing list