From c15c223ccdc7d28ae9dd240cfcb4a953f453b1fe Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Fri, 27 Aug 2010 00:35:59 +0000 Subject: 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. --- source/blender/makesrna/intern/rna_mesh.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c index 659e08a1878..741b5cbab81 100644 --- a/source/blender/makesrna/intern/rna_mesh.c +++ b/source/blender/makesrna/intern/rna_mesh.c @@ -1067,26 +1067,28 @@ static int rna_Mesh_tot_face_get(PointerRNA *ptr) 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; } -- cgit v1.2.3