Fix part I of T53977: Severe problem with multiple instances of a library (save and...
authorBastien Montagne <montagne29@wanadoo.fr>
Tue, 13 Feb 2018 19:58:40 +0000 (20:58 +0100)
committerBastien Montagne <montagne29@wanadoo.fr>
Fri, 16 Feb 2018 09:34:00 +0000 (10:34 +0100)
The issue was that when a same lib was found several times in loaded
.blend, we'd only keep the first occurence. But since Blender expects
next data-blocks to belong to last found library, we could actually
be adding data-blocks assigned to copies of the duplicated lib to
another, totally unrelated lib.

Those data-blocks were then obviously not found when actually loading
libs content, and lost.

Note that this only fix one part of the issue, current code can
generate several copies of same linked data-block now, will fix in
another commit.

source/blender/blenloader/intern/readfile.c

index 9aa67e8651f5a03c16b0231b8c599384cdbe0822..f45ff677ae3ba2e06d52cd6216bdfd1c927648ff 100644 (file)
@@ -7423,12 +7423,20 @@ static void direct_link_library(FileData *fd, Library *lib, Main *main)
                                
                                BLI_remlink(&main->library, lib);
                                MEM_freeN(lib);
-                               
-                               
+
+                               /* Now, since Blender always expect **latest** Main pointer from fd->mainlist to be the active library
+                                * Main pointer, where to add all non-library data-blocks found in file next, we have to switch that
+                                * 'dupli' found Main to latest position in the list!
+                                * Otherwise, you get weird disappearing linked data on a rather unconsistant basis.
+                                * See also T53977 for reproducible case. */
+                               BLI_remlink(fd->mainlist, newmain);
+                               BLI_addtail(fd->mainlist, newmain);
+
                                return;
                        }
                }
        }
+
        /* make sure we have full path in lib->filepath */
        BLI_strncpy(lib->filepath, lib->name, sizeof(lib->name));
        BLI_cleanup_path(fd->relabase, lib->filepath);