[Bf-blender-cvs] [fde9c3bc742] master: Fix: Incorrect versioning for float IDProperty default array

Hans Goudey noreply at git.blender.org
Tue Sep 21 18:20:50 CEST 2021


Commit: fde9c3bc74261aecdebe94dab9cfccf8cce66083
Author: Hans Goudey
Date:   Tue Sep 21 11:20:34 2021 -0500
Branches: master
https://developer.blender.org/rBfde9c3bc74261aecdebe94dab9cfccf8cce66083

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.

===================================================================

M	source/blender/blenloader/intern/versioning_300.c

===================================================================

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)) {



More information about the Bf-blender-cvs mailing list