svn merge ^/trunk/blender -r47398:47413
[blender.git] / source / blender / blenloader / intern / readfile.c
index 23939cc1aae4ec4bd560dfd85f2e2a24b7a51dcc..70bcf6c758ec51204e4133971681589165db3f45 100644 (file)
@@ -8004,10 +8004,17 @@ static void expand_doit(FileData *fd, Main *mainvar, void *old)
                                        
                                        /* Update: the issue is that in file reading, the oldnewmap is OK, but for existing data, it has to be
                                         * inserted in the map to be found! */
-                                       if (id->flag & LIB_PRE_EXISTING)
-                                               oldnewmap_insert(fd->libmap, bhead->old, id, 1);
-                                       
+
+                                       /* Update: previously it was checking for id->flag & LIB_PRE_EXISTING, however that does not affect file
+                                        * reading. For file reading we may need to insert it into the libmap as well, because you might have
+                                        * two files indirectly linking the same datablock, and in that case we need this in the libmap for the
+                                        * fd of both those files.
+                                        *
+                                        * The crash that this check avoided earlier was because bhead->code wasn't properly passed in, making
+                                        * change_idid_adr not detect the mapping was for an ID_ID datablock. */
+                                       oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
                                        change_idid_adr_fd(fd, bhead->old, id);
+                                       
                                        // commented because this can print way too much
                                        // if (G.debug & G_DEBUG) printf("expand_doit: already linked: %s lib: %s\n", id->name, lib->name);
                                }
@@ -8023,7 +8030,7 @@ static void expand_doit(FileData *fd, Main *mainvar, void *old)
                        else {
                                /* this is actually only needed on UI call? when ID was already read before, and another append
                                 * happens which invokes same ID... in that case the lookup table needs this entry */
-                               oldnewmap_insert(fd->libmap, bhead->old, id, 1);
+                               oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
                                // commented because this can print way too much
                                // if (G.debug & G_DEBUG) printf("expand: already read %s\n", id->name);
                        }
@@ -8908,7 +8915,7 @@ static ID *append_named_part(Main *mainl, FileData *fd, const char *idname, cons
                                else {
                                        /* already linked */
                                        printf("append: already linked\n");
-                                       oldnewmap_insert(fd->libmap, bhead->old, id, 1);
+                                       oldnewmap_insert(fd->libmap, bhead->old, id, bhead->code);
                                        if (id->flag & LIB_INDIRECT) {
                                                id->flag -= LIB_INDIRECT;
                                                id->flag |= LIB_EXTERN;