From c820f9b85c2b8e8578abfebf023715fb6c95ede7 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Tue, 26 Sep 2023 16:44:28 +0200 Subject: [PATCH] Fix #112649: Crash loading early 2.80 blend file without a scene collection. Caused by 23835a393c, which removed entirely the transitive `SceneCollection` struct and associated versioning code. This was used in very early 2.80 development period (up to 2.80 sub 14 apparently) instead of the current 'master collection'. The purpose of this commit is only to fix the crash, not to restore the support for this old, deprecated and never-released type of data. --- .../blenloader/intern/versioning_280.cc | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/source/blender/blenloader/intern/versioning_280.cc b/source/blender/blenloader/intern/versioning_280.cc index ac9c22b3108..acd77dcf107 100644 --- a/source/blender/blenloader/intern/versioning_280.cc +++ b/source/blender/blenloader/intern/versioning_280.cc @@ -2410,6 +2410,32 @@ void do_versions_after_linking_280(FileData *fd, Main *bmain) } } + if (!MAIN_VERSION_FILE_ATLEAST(bmain, 280, 14)) { + /* This code fixes crashes when loading early 2.80 dev files, due to the lack of a master + * collection after removal of the versioning code handling the 'SceneCollection' data that was + * part of the very early 2.80 development (commit 23835a393c). + * + * NOTE: This code only ensures that there is no crash, since the whole collection hierarchy + * from these files remain lost, these files will still need a lot of manual work if one want + * to get them working properly again. Or just open and save them with an older release of + * Blender (up to 3.6 included). */ + LISTBASE_FOREACH (Scene *, scene, &bmain->scenes) { + if (scene->master_collection == nullptr) { + scene->master_collection = BKE_collection_master_add(scene); + /* #BKE_layer_collection_sync accepts missing viewlayer in a scene, but not invalid ones + * where the first viewlayer's layercollection would not be for the Scene's master + * collection. */ + LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) { + if (LayerCollection *first_layer_collection = static_cast( + view_layer->layer_collections.first)) + { + first_layer_collection->collection = scene->master_collection; + } + } + } + } + } + /* Update Curve object Shape Key data layout to include the Radius property */ if (!MAIN_VERSION_FILE_ATLEAST(bmain, 280, 23)) { LISTBASE_FOREACH (Curve *, cu, &bmain->curves) {