From 818c9e524d82d3eff40504e7d0e5293961983155 Mon Sep 17 00:00:00 2001 From: Hans Goudey Date: Wed, 14 Sep 2022 11:31:52 -0500 Subject: Fix: Mesh SoA format conversion skips versioning Converting to the SoA format (T95965) immediately when reading meshes means that none of the changes from versioning would be applied first. This means important fixes like f14995aba70a aren't properly applied, so modifications could be done to invalid CustomData. To fix this, move the SoA changes into versioning code, in a new versioning_400.cc file. Differential Revision: https://developer.blender.org/D15919 --- source/blender/blenloader/CMakeLists.txt | 1 + source/blender/blenloader/intern/readfile.c | 2 + source/blender/blenloader/intern/readfile.h | 9 ++++ source/blender/blenloader/intern/versioning_400.cc | 52 ++++++++++++++++++++++ 4 files changed, 64 insertions(+) create mode 100644 source/blender/blenloader/intern/versioning_400.cc (limited to 'source/blender/blenloader') diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt index f8bf97b17e9..f6c43a266cd 100644 --- a/source/blender/blenloader/CMakeLists.txt +++ b/source/blender/blenloader/CMakeLists.txt @@ -44,6 +44,7 @@ set(SRC intern/versioning_280.c intern/versioning_290.c intern/versioning_300.c + intern/versioning_400.cc intern/versioning_common.cc intern/versioning_cycles.c intern/versioning_defaults.c diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index bf2017b80f4..850dabf8078 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -73,6 +73,7 @@ #include "BKE_main.h" /* for Main */ #include "BKE_main_idmap.h" #include "BKE_material.h" +#include "BKE_mesh.h" #include "BKE_modifier.h" #include "BKE_node.h" /* for tree type defines */ #include "BKE_object.h" @@ -3599,6 +3600,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main) blo_do_versions_280(fd, lib, main); blo_do_versions_290(fd, lib, main); blo_do_versions_300(fd, lib, main); + blo_do_versions_400(fd, lib, main); blo_do_versions_cycles(fd, lib, main); /* WATCH IT!!!: pointers from libdata have not been converted yet here! */ diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h index 4522adb2aef..00d22012066 100644 --- a/source/blender/blenloader/intern/readfile.h +++ b/source/blender/blenloader/intern/readfile.h @@ -17,6 +17,10 @@ #include "DNA_space_types.h" #include "DNA_windowmanager_types.h" /* for eReportType */ +#ifdef __cplusplus +extern "C" { +#endif + struct BLI_mmap_file; struct BLOCacheStorage; struct IDNameLib_Map; @@ -207,6 +211,7 @@ void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main * void blo_do_versions_280(struct FileData *fd, struct Library *lib, struct Main *bmain); void blo_do_versions_290(struct FileData *fd, struct Library *lib, struct Main *bmain); void blo_do_versions_300(struct FileData *fd, struct Library *lib, struct Main *bmain); +void blo_do_versions_400(struct FileData *fd, struct Library *lib, struct Main *bmain); void blo_do_versions_cycles(struct FileData *fd, struct Library *lib, struct Main *bmain); void do_versions_after_linking_250(struct Main *bmain); @@ -224,3 +229,7 @@ void do_versions_after_linking_cycles(struct Main *bmain); * but better use that nasty hack in do_version than readfile itself. */ void *blo_read_get_new_globaldata_address(struct FileData *fd, const void *adr); + +#ifdef __cplusplus +} +#endif diff --git a/source/blender/blenloader/intern/versioning_400.cc b/source/blender/blenloader/intern/versioning_400.cc new file mode 100644 index 00000000000..a5e1791d24c --- /dev/null +++ b/source/blender/blenloader/intern/versioning_400.cc @@ -0,0 +1,52 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +/** \file + * \ingroup blenloader + */ + +#define DNA_DEPRECATED_ALLOW + +#include "CLG_log.h" + +#include "BKE_main.h" +#include "BKE_mesh_legacy_convert.h" + +#include "BLO_readfile.h" + +#include "readfile.h" + +#include "versioning_common.h" + +// static CLG_LogRef LOG = {"blo.readfile.doversion"}; + +static void version_mesh_legacy_to_struct_of_array_format(Mesh &mesh) +{ + BKE_mesh_legacy_convert_flags_to_hide_layers(&mesh); + BKE_mesh_legacy_convert_mpoly_to_material_indices(&mesh); + BKE_mesh_legacy_bevel_weight_to_layers(&mesh); +} + +void blo_do_versions_400(FileData * /*fd*/, Library * /*lib*/, Main *bmain) +{ + // if (!MAIN_VERSION_ATLEAST(bmain, 400, 0)) { + /* This is done here because we will continue to write with the old format until 4.0, so we need + * to convert even "current" files. Keep the check commented out for now so the versioning isn't + * turned off right after the 4.0 bump. */ + LISTBASE_FOREACH (Mesh *, mesh, &bmain->meshes) { + version_mesh_legacy_to_struct_of_array_format(*mesh); + } + // } + + /** + * Versioning code until next subversion bump goes here. + * + * \note Be sure to check when bumping the version: + * - "versioning_userdef.c", #blo_do_versions_userdef + * - "versioning_userdef.c", #do_versions_theme + * + * \note Keep this message at the bottom of the function. + */ + { + /* Keep this block, even when empty. */ + } +} -- cgit v1.2.3