From f14995aba70a46e2629faab6a2d74aef53205d90 Mon Sep 17 00:00:00 2001 From: Jacques Lucke Date: Wed, 16 Sep 2020 12:26:16 +0200 Subject: Fix: add versioning to fix incorrectly written customdata Reviewers: campbellbarton Differential Revision: https://developer.blender.org/D8903 --- source/blender/blenkernel/BKE_blender_version.h | 2 +- source/blender/blenloader/intern/versioning_290.c | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) (limited to 'source/blender') 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. * -- cgit v1.2.3