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

@ -36,54 +36,69 @@
/* Define the accessors for a basic CustomDataLayer collection */
#define DEFINE_CUSTOMDATA_LAYER_COLLECTION(collection_name, customdata_type, layer_type) \
\
/* check */ \
static int rna_##collection_name##_check(CollectionPropertyIterator *iter, void *data) \
{ \
CustomDataLayer *layer = (CustomDataLayer*)data; \
return (layer->type != layer_type); \
} \
\
static void rna_Mesh_##collection_name##s_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) \
/* begin */ \
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); \
if (data) { \
rna_iterator_array_begin(iter, \
(void *)data->layers, sizeof(CustomDataLayer), \
data->totlayer, 0, \
rna_##collection_name##_check); \
} \
\
else { \
rna_iterator_array_begin(iter, NULL, 0, 0, 0, NULL); \
} \
} \
/* length */ \
static int rna_Mesh_##collection_name##s_length(PointerRNA *ptr) \
{ \
CustomData *data = rna_mesh_##customdata_type(ptr); \
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
(active, render, clone, stencil, etc) */
#define DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(collection_name, customdata_type, layer_type, active_type, layer_rna_type) \
* (active, render, clone, stencil, etc) */
#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) \
{ \
CustomData *data = rna_mesh_##customdata_type(ptr); \
CustomDataLayer *cdl; \
if (data) { \
int index = CustomData_get_##active_type##_layer_index(data, layer_type); \
CustomDataLayer *cdl = (index == -1)? NULL: &data->layers[index]; \
\
} \
else { \
cdl = NULL; \
} \
return rna_pointer_inherit_refine(ptr, &RNA_##layer_rna_type, cdl); \
} \
\
static void rna_Mesh_##collection_name##_##active_type##_set(PointerRNA *ptr, PointerRNA value) \
static void rna_Mesh_##collection_name##_##active_type##_set(PointerRNA *ptr, \
PointerRNA value) \
{ \
Mesh *me = rna_mesh(ptr); \
CustomData *data = rna_mesh_##customdata_type(ptr); \
CustomDataLayer *cdl; \
int a; \
\
if (data) { \
for (cdl = data->layers, a = 0; a<data->totlayer; cdl++, a++) { \
if (value.data == cdl) { \
CustomData_set_layer_##active_type##_index(data, layer_type, a); \
@ -91,21 +106,23 @@
return; \
} \
} \
} \
} \
\
static int rna_Mesh_##collection_name##_##active_type##_index_get(PointerRNA *ptr) \
{ \
CustomData *data = rna_mesh_##customdata_type(ptr); \
return CustomData_get_##active_type##_layer(data, layer_type); \
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) \
{ \
Mesh *me = rna_mesh(ptr); \
CustomData *data = rna_mesh_##customdata_type(ptr); \
\
if (data) { \
CustomData_set_layer_##active_type(data, layer_type, value); \
mesh_update_customdata_pointers(me, TRUE); \
} \
}
#endif /* __RNA_MESH_UTILS_H__ */