Fix: add versioning to fix incorrectly written customdata

Reviewers: campbellbarton

Differential Revision: https://developer.blender.org/D8903
This commit is contained in:
2020-09-16 12:26:16 +02:00
parent 27a5da4dc3
commit f14995aba7
2 changed files with 21 additions and 1 deletions

View File

@@ -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

View File

@@ -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.
*