diff options
author | Hans Goudey <h.goudey@me.com> | 2021-09-21 19:20:34 +0300 |
---|---|---|
committer | Hans Goudey <h.goudey@me.com> | 2021-09-21 19:20:34 +0300 |
commit | fde9c3bc74261aecdebe94dab9cfccf8cce66083 (patch) | |
tree | b8c461d46780d7776b93405e8309964d4c494569 /source | |
parent | 66dbe6e55a1d3e412ad6ce4fd77a545a03e767d7 (diff) |
Fix: Incorrect versioning for float IDProperty default array
The versioning has to have different behavior for when the old default
value had a float type rather than a double type. Also use memcpy
rather than dupalloc, since it's a bit clearer.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenloader/intern/versioning_300.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/source/blender/blenloader/intern/versioning_300.c b/source/blender/blenloader/intern/versioning_300.c index 4dc6a0ecea6..791b5d52d97 100644 --- a/source/blender/blenloader/intern/versioning_300.c +++ b/source/blender/blenloader/intern/versioning_300.c @@ -110,7 +110,8 @@ static void version_idproperty_move_data_int(IDPropertyUIDataInt *ui_data, if (default_value != NULL) { if (default_value->type == IDP_ARRAY) { if (default_value->subtype == IDP_INT) { - ui_data->default_array = MEM_dupallocN(IDP_Array(default_value)); + ui_data->default_array = MEM_malloc_arrayN(default_value->len, sizeof(int), __func__); + memcpy(ui_data->default_array, IDP_Array(default_value), sizeof(int) * default_value->len); ui_data->default_array_len = default_value->len; } } @@ -152,9 +153,18 @@ static void version_idproperty_move_data_float(IDPropertyUIDataFloat *ui_data, IDProperty *default_value = IDP_GetPropertyFromGroup(prop_ui_data, "default"); if (default_value != NULL) { if (default_value->type == IDP_ARRAY) { - if (ELEM(default_value->subtype, IDP_FLOAT, IDP_DOUBLE)) { - ui_data->default_array = MEM_dupallocN(IDP_Array(default_value)); - ui_data->default_array_len = default_value->len; + const int size = default_value->len; + ui_data->default_array_len = size; + if (default_value->subtype == IDP_FLOAT) { + ui_data->default_array = MEM_malloc_arrayN(size, sizeof(double), __func__); + const float *old_default_array = IDP_Array(default_value); + for (int i = 0; i < ui_data->default_array_len; i++) { + ui_data->default_array[i] = (double)old_default_array[i]; + } + } + else if (default_value->subtype == IDP_DOUBLE) { + ui_data->default_array = MEM_malloc_arrayN(size, sizeof(double), __func__); + memcpy(ui_data->default_array, IDP_Array(default_value), sizeof(double) * size); } } else if (ELEM(default_value->type, IDP_DOUBLE, IDP_FLOAT)) { |