diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-01-08 18:25:17 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-01-08 18:25:17 +0400 |
commit | e62bc29a9b5a4bb69547bb565e9793fca6df5b76 (patch) | |
tree | be930627645be7deca26d46f33f54758143b8dbb /source/blender/blenkernel/intern/customdata.c | |
parent | 5042a0a8ef8bb4a3247b924bd1f34710d0a9fa0f (diff) |
fix [#33792] Accessing a bmesh object created by from_object crashes blender
Issue was customdata wasnt being initialized for layers in the destination BMesh but not in the source data.
Diffstat (limited to 'source/blender/blenkernel/intern/customdata.c')
-rw-r--r-- | source/blender/blenkernel/intern/customdata.c | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c index 832c1979a51..19624e8a2b9 100644 --- a/source/blender/blenkernel/intern/customdata.c +++ b/source/blender/blenkernel/intern/customdata.c @@ -2660,27 +2660,40 @@ void CustomData_bmesh_interp(CustomData *data, void **src_blocks, const float *w if (count > SOURCE_BUF_SIZE) MEM_freeN(sources); } -void CustomData_bmesh_set_default(CustomData *data, void **block) +static void CustomData_bmesh_set_default_n(CustomData *data, void **block, int n) { const LayerTypeInfo *typeInfo; + int offset = data->layers[n].offset; + + typeInfo = layerType_getInfo(data->layers[n].type); + + if (typeInfo->set_default) { + typeInfo->set_default((char *)*block + offset, 1); + } + else { + memset((char *)*block + offset, 0, typeInfo->size); + } +} + +void CustomData_bmesh_set_default(CustomData *data, void **block) +{ int i; if (*block == NULL) CustomData_bmesh_alloc_block(data, block); for (i = 0; i < data->totlayer; ++i) { - int offset = data->layers[i].offset; - - typeInfo = layerType_getInfo(data->layers[i].type); - - if (typeInfo->set_default) - typeInfo->set_default((char *)*block + offset, 1); - else memset((char *)*block + offset, 0, typeInfo->size); + CustomData_bmesh_set_default_n(data, block, i); } } +/** + * \param use_default_init initializes data which can't be copied, + * typically you'll want to use this if the BM_xxx create function + * is called with BM_CREATE_SKIP_CD flag + */ void CustomData_to_bmesh_block(const CustomData *source, CustomData *dest, - int src_index, void **dest_block) + int src_index, void **dest_block, bool use_default_init) { const LayerTypeInfo *typeInfo; int dest_i, src_i, src_offset; @@ -2696,11 +2709,14 @@ void CustomData_to_bmesh_block(const CustomData *source, CustomData *dest, * (this should work because layers are ordered by type) */ while (dest_i < dest->totlayer && dest->layers[dest_i].type < source->layers[src_i].type) { + if (use_default_init) { + CustomData_bmesh_set_default_n(dest, dest_block, dest_i); + } dest_i++; } /* if there are no more dest layers, we're done */ - if (dest_i >= dest->totlayer) return; + if (dest_i >= dest->totlayer) break; /* if we found a matching layer, copy the data */ if (dest->layers[dest_i].type == source->layers[src_i].type) { @@ -2723,6 +2739,13 @@ void CustomData_to_bmesh_block(const CustomData *source, CustomData *dest, dest_i++; } } + + if (use_default_init) { + while (dest_i < dest->totlayer) { + CustomData_bmesh_set_default_n(dest, dest_block, dest_i); + dest_i++; + } + } } void CustomData_from_bmesh_block(const CustomData *source, CustomData *dest, |