[Bf-blender-cvs] [f14995aba70] master: Fix: add versioning to fix incorrectly written customdata

Jacques Lucke noreply at git.blender.org
Wed Sep 16 12:27:03 CEST 2020


Commit: f14995aba70a46e2629faab6a2d74aef53205d90
Author: Jacques Lucke
Date:   Wed Sep 16 12:26:16 2020 +0200
Branches: master
https://developer.blender.org/rBf14995aba70a46e2629faab6a2d74aef53205d90

Fix: add versioning to fix incorrectly written customdata

Reviewers: campbellbarton

Differential Revision: https://developer.blender.org/D8903

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

M	source/blender/blenkernel/BKE_blender_version.h
M	source/blender/blenloader/intern/versioning_290.c

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

diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index 19350e3e3b0..40a4a2ca0ee 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -39,7 +39,7 @@ extern "C" {
 
 /* Blender file format version. */
 #define BLENDER_FILE_VERSION BLENDER_VERSION
-#define BLENDER_FILE_SUBVERSION 3
+#define BLENDER_FILE_SUBVERSION 4
 
 /* Minimum Blender version that supports reading file written with the current
  * version. Older Blender versions will test this and show a warning if the file
diff --git a/source/blender/blenloader/intern/versioning_290.c b/source/blender/blenloader/intern/versioning_290.c
index aaf4ecbf255..7f2b1714245 100644
--- a/source/blender/blenloader/intern/versioning_290.c
+++ b/source/blender/blenloader/intern/versioning_290.c
@@ -33,6 +33,7 @@
 #include "DNA_gpencil_modifier_types.h"
 #include "DNA_gpencil_types.h"
 #include "DNA_hair_types.h"
+#include "DNA_mesh_types.h"
 #include "DNA_modifier_types.h"
 #include "DNA_object_types.h"
 #include "DNA_pointcloud_types.h"
@@ -47,6 +48,8 @@
 #include "BKE_main.h"
 #include "BKE_node.h"
 
+#include "MEM_guardedalloc.h"
+
 #include "BLO_readfile.h"
 #include "readfile.h"
 
@@ -659,6 +662,23 @@ void blo_do_versions_290(FileData *fd, Library *UNUSED(lib), Main *bmain)
     }
   }
 
+  if (!MAIN_VERSION_ATLEAST(bmain, 291, 4) && MAIN_VERSION_ATLEAST(bmain, 291, 1)) {
+    /* Due to a48d78ce07f4f, CustomData.totlayer and CustomData.maxlayer has been written
+     * incorrectly. Fortunately, the size of the layers array has been written to the .blend file
+     * as well, so we can reconstruct totlayer and maxlayer from that. */
+    LISTBASE_FOREACH (Mesh *, mesh, &bmain->meshes) {
+      mesh->vdata.totlayer = mesh->vdata.maxlayer = MEM_allocN_len(mesh->vdata.layers) /
+                                                    sizeof(CustomDataLayer);
+      mesh->edata.totlayer = mesh->edata.maxlayer = MEM_allocN_len(mesh->edata.layers) /
+                                                    sizeof(CustomDataLayer);
+      /* We can be sure that mesh->fdata is empty for files written by 2.90. */
+      mesh->ldata.totlayer = mesh->ldata.maxlayer = MEM_allocN_len(mesh->ldata.layers) /
+                                                    sizeof(CustomDataLayer);
+      mesh->pdata.totlayer = mesh->pdata.maxlayer = MEM_allocN_len(mesh->pdata.layers) /
+                                                    sizeof(CustomDataLayer);
+    }
+  }
+
   /**
    * Versioning code until next subversion bump goes here.
    *



More information about the Bf-blender-cvs mailing list