fix [#30500] Mesh.tessface_uv_textures or Mesh.tessface_vertex_colors crash on access in editmode

just missing NULL checks on face data.
This commit is contained in:
Campbell Barton 2012-03-10 05:20:41 +00:00
parent 24b676e370
commit 064a333561

@ -35,77 +35,94 @@
/* Macros to help reduce code clutter in rna_mesh.c */ /* Macros to help reduce code clutter in rna_mesh.c */
/* Define the accessors for a basic CustomDataLayer collection */ /* Define the accessors for a basic CustomDataLayer collection */
#define DEFINE_CUSTOMDATA_LAYER_COLLECTION(collection_name, customdata_type, layer_type) \ #define DEFINE_CUSTOMDATA_LAYER_COLLECTION(collection_name, customdata_type, layer_type) \
\ /* check */ \
static int rna_##collection_name##_check(CollectionPropertyIterator *iter, void *data) \ static int rna_##collection_name##_check(CollectionPropertyIterator *iter, void *data) \
{ \ { \
CustomDataLayer *layer = (CustomDataLayer*)data; \ CustomDataLayer *layer = (CustomDataLayer*)data; \
return (layer->type != layer_type); \ return (layer->type != layer_type); \
} \ } \
\ /* begin */ \
static void rna_Mesh_##collection_name##s_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) \ static void rna_Mesh_##collection_name##s_begin(CollectionPropertyIterator *iter, \
{ \ PointerRNA *ptr) \
CustomData *data = rna_mesh_##customdata_type(ptr); \ { \
rna_iterator_array_begin(iter, (void*)data->layers, sizeof(CustomDataLayer), data->totlayer, 0, rna_##collection_name##_check); \ CustomData *data = rna_mesh_##customdata_type(ptr); \
} \ if (data) { \
\ rna_iterator_array_begin(iter, \
static int rna_Mesh_##collection_name##s_length(PointerRNA *ptr) \ (void *)data->layers, sizeof(CustomDataLayer), \
{ \ data->totlayer, 0, \
CustomData *data = rna_mesh_##customdata_type(ptr); \ rna_##collection_name##_check); \
return data ? CustomData_number_of_layers(data, layer_type) : 0; \ } \
} \ else { \
\ rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL); \
static void rna_Mesh_##collection_name##_index_range(PointerRNA *ptr, int *min, int *max) \ } \
{ \ } \
CustomData *data = rna_mesh_##customdata_type(ptr); \ /* length */ \
\ static int rna_Mesh_##collection_name##s_length(PointerRNA *ptr) \
*min = 0; \ { \
*max = data ? CustomData_number_of_layers(data, layer_type) - 1 : 0; \ CustomData *data = rna_mesh_##customdata_type(ptr); \
*max = MAX2(0, *max); \ return data ? CustomData_number_of_layers(data, layer_type) : 0; \
} \
/* index range */ \
static void rna_Mesh_##collection_name##_index_range(PointerRNA *ptr, int *min, int *max) \
{ \
CustomData *data = rna_mesh_##customdata_type(ptr); \
*min = 0; \
*max = data ? CustomData_number_of_layers(data, layer_type) - 1 : 0; \
*max = MAX2(0, *max); \
} }
/* Define the accessors for special CustomDataLayers in the collection /* Define the accessors for special CustomDataLayers in the collection
(active, render, clone, stencil, etc) */ * (active, render, clone, stencil, etc) */
#define DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(collection_name, customdata_type, layer_type, active_type, layer_rna_type) \ #define DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(collection_name, customdata_type, \
\ layer_type, active_type, layer_rna_type) \
static PointerRNA rna_Mesh_##collection_name##_##active_type##_get(PointerRNA *ptr) \ \
{ \ static PointerRNA rna_Mesh_##collection_name##_##active_type##_get(PointerRNA *ptr) \
CustomData *data = rna_mesh_##customdata_type(ptr); \ { \
int index = CustomData_get_##active_type##_layer_index(data, layer_type); \ CustomData *data = rna_mesh_##customdata_type(ptr); \
CustomDataLayer *cdl = (index == -1)? NULL: &data->layers[index]; \ CustomDataLayer *cdl; \
\ if (data) { \
return rna_pointer_inherit_refine(ptr, &RNA_##layer_rna_type, cdl); \ int index = CustomData_get_##active_type##_layer_index(data, layer_type); \
} \ CustomDataLayer *cdl = (index == -1)? NULL: &data->layers[index]; \
\ } \
static void rna_Mesh_##collection_name##_##active_type##_set(PointerRNA *ptr, PointerRNA value) \ else { \
{ \ cdl = NULL; \
Mesh *me = rna_mesh(ptr); \ } \
CustomData *data = rna_mesh_##customdata_type(ptr); \ return rna_pointer_inherit_refine(ptr, &RNA_##layer_rna_type, cdl); \
CustomDataLayer *cdl; \ } \
int a; \ \
\ static void rna_Mesh_##collection_name##_##active_type##_set(PointerRNA *ptr, \
for (cdl = data->layers, a = 0; a<data->totlayer; cdl++, a++) { \ PointerRNA value) \
if (value.data == cdl) { \ { \
CustomData_set_layer_##active_type##_index(data, layer_type, a); \ Mesh *me = rna_mesh(ptr); \
mesh_update_customdata_pointers(me, TRUE); \ CustomData *data = rna_mesh_##customdata_type(ptr); \
return; \ CustomDataLayer *cdl; \
} \ int a; \
} \ if (data) { \
} \ for (cdl = data->layers, a = 0; a<data->totlayer; cdl++, a++) { \
\ if (value.data == cdl) { \
static int rna_Mesh_##collection_name##_##active_type##_index_get(PointerRNA *ptr) \ CustomData_set_layer_##active_type##_index(data, layer_type, a); \
{ \ mesh_update_customdata_pointers(me, TRUE); \
CustomData *data = rna_mesh_##customdata_type(ptr); \ return; \
return CustomData_get_##active_type##_layer(data, layer_type); \ } \
} \ } \
\ } \
} \
\
static int rna_Mesh_##collection_name##_##active_type##_index_get(PointerRNA *ptr) \
{ \
CustomData *data = rna_mesh_##customdata_type(ptr); \
return (data == NULL) ? 0 : CustomData_get_##active_type##_layer(data, layer_type); \
} \
\
static void rna_Mesh_##collection_name##_##active_type##_index_set(PointerRNA *ptr, int value) \ static void rna_Mesh_##collection_name##_##active_type##_index_set(PointerRNA *ptr, int value) \
{ \ { \
Mesh *me = rna_mesh(ptr); \ Mesh *me = rna_mesh(ptr); \
CustomData *data = rna_mesh_##customdata_type(ptr); \ CustomData *data = rna_mesh_##customdata_type(ptr); \
\ if (data) { \
CustomData_set_layer_##active_type(data, layer_type, value); \ CustomData_set_layer_##active_type(data, layer_type, value); \
mesh_update_customdata_pointers(me, TRUE); \ mesh_update_customdata_pointers(me, TRUE); \
} \
} }
#endif /* __RNA_MESH_UTILS_H__ */ #endif /* __RNA_MESH_UTILS_H__ */