Commit: cb3c9cba49290bf12116033a7ea151cad352cf76
Author: Brecht Van Lommel
Date:   Thu May 24 12:01:40 2018 +0200
Branches: blender2.8
https://developer.blender.org/rBcb3c9cba49290bf12116033a7ea151cad352cf76

Fix T55171: crash with undo and linked collections.

Collections created in library file versioning need to be set as coming
from the library, otherwise they get freed on undo.

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

M       source/blender/blenloader/intern/readfile.c
M       source/blender/blenloader/intern/versioning_280.c

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

diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 70c898a374e..f0c6d314c26 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5717,7 +5717,6 @@ static void lib_link_collection_data(FileData *fd, 
Library *lib, Collection *col
                cob->ob = newlibadr_us(fd, lib, cob->ob);
 
                if (cob->ob == NULL) {
-                       BLI_assert(!"Collection linked object got lost"); // 
TODO: remove, only for testing now
                        BLI_freelinkN(&collection->gobject, cob);
                }
        }
@@ -5729,7 +5728,6 @@ static void lib_link_collection_data(FileData *fd, 
Library *lib, Collection *col
                if (child->collection == NULL ||
                    BKE_collection_find_cycle(collection, child->collection))
                {
-                       BLI_assert(!"Collection child got lost"); // TODO: 
remove, only for testing now
                        BLI_freelinkN(&collection->children, child);
                }
                else {
diff --git a/source/blender/blenloader/intern/versioning_280.c 
b/source/blender/blenloader/intern/versioning_280.c
index 7bb20c38308..a25c744afc4 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -262,6 +262,7 @@ static void do_version_layer_collection_post(
 
 static void do_version_scene_collection_convert(
         Main *bmain,
+        ID *id,
         SceneCollection *sc,
         Collection *collection,
         GHash *collection_map)
@@ -273,7 +274,8 @@ static void do_version_scene_collection_convert(
        for (SceneCollection *nsc = sc->scene_collections.first; nsc;) {
                SceneCollection *nsc_next = nsc->next;
                Collection *ncollection = BKE_collection_add(bmain, collection, 
nsc->name);
-               do_version_scene_collection_convert(bmain, nsc, ncollection, 
collection_map);
+               ncollection->id.lib = id->lib;
+               do_version_scene_collection_convert(bmain, id, nsc, 
ncollection, collection_map);
                nsc = nsc_next;
        }
 
@@ -293,7 +295,7 @@ static void do_version_group_collection_to_collection(Main 
*bmain, Collection *g
 {
        /* Convert old 2.8 group collections to new unified collections. */
        if (group->collection) {
-               do_version_scene_collection_convert(bmain, group->collection, 
group, NULL);
+               do_version_scene_collection_convert(bmain, &group->id, 
group->collection, group, NULL);
        }
 
        group->collection = NULL;
@@ -317,7 +319,7 @@ static void do_version_scene_collection_to_collection(Main 
*bmain, Scene *scene)
        /* Convert scene collections. */
        GHash *collection_map = BLI_ghash_new(BLI_ghashutil_ptrhash, 
BLI_ghashutil_ptrcmp, __func__);
        if (scene->collection) {
-               do_version_scene_collection_convert(bmain, scene->collection, 
scene->master_collection, collection_map);
+               do_version_scene_collection_convert(bmain, &scene->id, 
scene->collection, scene->master_collection, collection_map);
                scene->collection = NULL;
        }
 
@@ -434,6 +436,7 @@ static void do_version_layers_to_collections(Main *bmain, 
Scene *scene)
                                                             
collections[DO_VERSION_COLLECTION_VISIBLE].suffix);
 
                                                Collection *collection = 
BKE_collection_add(bmain, collection_master, name);
+                                               collection->id.lib = 
scene->id.lib;
                                                collection->flag |= 
collections[DO_VERSION_COLLECTION_VISIBLE].flag;
                                                
collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer] = collection;
                                                
collections[DO_VERSION_COLLECTION_VISIBLE].created |= (1 << layer);
@@ -453,6 +456,7 @@ static void do_version_layers_to_collections(Main *bmain, 
Scene *scene)
                                                             
collections[collection_index].suffix);
 
                                                Collection *collection = 
BKE_collection_add(bmain, collection_parent, name);
+                                               collection->id.lib = 
scene->id.lib;
                                                collection->flag |= 
collections[collection_index].flag;
                                                
collections[collection_index].collections[layer] = collection;
                                                
collections[collection_index].created |= (1 << layer);
@@ -676,12 +680,14 @@ void do_versions_after_linking_280(Main *main)
 
                /* Convert group layer visibility flags to hidden nested 
collection. */
                for (Collection *collection = main->collection.first; 
collection; collection = collection->id.next) {
-                       Collection *collection_hidden = NULL;
+                       /* Add fake user for all existing groups. */
+                       id_fake_user_set(&collection->id);
 
                        if (collection->flag & (COLLECTION_RESTRICT_VIEW | 
COLLECTION_RESTRICT_RENDER)) {
                                continue;
                        }
 
+                       Collection *collection_hidden = NULL;
                        for (CollectionObject *cob = collection->gobject.first, 
*cob_next = NULL; cob; cob = cob_next) {
                                cob_next = cob->next;
                                Object *ob = cob->ob;
@@ -689,6 +695,7 @@ void do_versions_after_linking_280(Main *main)
                                if (!(ob->lay & collection->layer)) {
                                        if (collection_hidden == NULL) {
                                                collection_hidden = 
BKE_collection_add(main, collection, "Hidden");
+                                               collection_hidden->id.lib = 
collection->id.lib;
                                                collection_hidden->flag |= 
COLLECTION_RESTRICT_VIEW | COLLECTION_RESTRICT_RENDER;
                                        }
 
@@ -696,9 +703,6 @@ void do_versions_after_linking_280(Main *main)
                                        BKE_collection_object_remove(main, 
collection, ob, true);
                                }
                        }
-
-                       /* Add fake user for all existing groups. */
-                       id_fake_user_set(&collection->id);
                }
 
                /* Convert layers to collections. */

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to