[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [31601] trunk/blender/source/blender/ makesrna/intern/rna_mesh.c: Fix for Mesh.uv_textures.new(name="my_uv") returning the wrong uvmap - reported by Vitor Balbio - not in tracker.

Dalai Felinto dfelinto at gmail.com
Fri Aug 27 02:35:59 CEST 2010


Revision: 31601
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=31601
Author:   dfelinto
Date:     2010-08-27 02:35:59 +0200 (Fri, 27 Aug 2010)

Log Message:
-----------
Fix for Mesh.uv_textures.new(name="my_uv") returning the wrong uvmap - reported by Vitor Balbio - not in tracker.

The code was taking the last layer, but that is only valid if the mesh has only one kind of CustomData types (e.g. only UVMaps or only VertexColors). The solution I found is to call CustomData_get_named_layer_index instead. To avoid some situations where an uv with this name may already exist and the number of UVs is already the limit we are returning a CDL only when the texture is properly created.

As a bonus that also fixes the same problem with VertexColor.

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/intern/rna_mesh.c

Modified: trunk/blender/source/blender/makesrna/intern/rna_mesh.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_mesh.c	2010-08-27 00:05:00 UTC (rev 31600)
+++ trunk/blender/source/blender/makesrna/intern/rna_mesh.c	2010-08-27 00:35:59 UTC (rev 31601)
@@ -1067,26 +1067,28 @@
 static CustomDataLayer *rna_Mesh_vertex_color_new(struct Mesh *me, struct bContext *C, char *name)
 {
 	CustomData *fdata;
-	CustomDataLayer *cdl;
+	CustomDataLayer *cdl= NULL;
 	int index;
-	ED_mesh_color_add(C, NULL, NULL, me, name, FALSE);
 
-	fdata= rna_mesh_fdata(me);
-	index= CustomData_number_of_layers(fdata, CD_MCOL) - 1;
-	cdl= (index == -1)? NULL: &fdata->layers[index];
+	if(ED_mesh_color_add(C, NULL, NULL, me, name, FALSE)) {
+		fdata= rna_mesh_fdata(me);
+		index= CustomData_get_named_layer_index(fdata, CD_MCOL, name);
+		cdl= (index == -1)? NULL: &fdata->layers[index];
+	}
 	return cdl;
 }
 
 static CustomDataLayer *rna_Mesh_uv_texture_new(struct Mesh *me, struct bContext *C, char *name)
 {
 	CustomData *fdata;
-	CustomDataLayer *cdl;
+	CustomDataLayer *cdl= NULL;
 	int index;
-	ED_mesh_uv_texture_add(C, NULL, NULL, me, name, FALSE);
 
-	fdata= rna_mesh_fdata(me);
-	index= CustomData_number_of_layers(fdata, CD_MTFACE) - 1;
-	cdl= (index == -1)? NULL: &fdata->layers[index];
+	if(ED_mesh_uv_texture_add(C, NULL, NULL, me, name, FALSE)) {
+		fdata= rna_mesh_fdata(me);
+		index= CustomData_get_named_layer_index(fdata, CD_MTFACE, name);
+		cdl= (index == -1)? NULL: &fdata->layers[index];
+	}
 	return cdl;
 }
 





More information about the Bf-blender-cvs mailing list