[Bf-blender-cvs] [396bf6ca781] master: Fix T73164: Undo does not always properly clear no-more-used library data.

Bastien Montagne noreply at git.blender.org
Mon May 25 17:44:33 CEST 2020


Commit: 396bf6ca781fdfa79544c92f3d6bdff52c96fedf
Author: Bastien Montagne
Date:   Mon May 25 17:39:16 2020 +0200
Branches: master
https://developer.blender.org/rB396bf6ca781fdfa79544c92f3d6bdff52c96fedf

Fix T73164: Undo does not always properly clear no-more-used library data.

Solution is actually very simple, and even makes existing code simpler:
just write all lib IDs when storing and undo step. That way we do not
have to guess which indirectly used library should be kept or not after
an undo step reading.

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

M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/writefile.c

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

diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index adf7db0267e..1309b3e3c33 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -428,41 +428,6 @@ BlendFileData *BLO_read_from_memfile(Main *oldmain,
      * but oldmain itself shall *never* be 'transferred' to new mainlist! */
     BLI_assert(old_mainlist.first == oldmain);
 
-    if (bfd && old_mainlist.first != old_mainlist.last) {
-      /* Even though directly used libs have been already moved to new main,
-       * indirect ones have not.
-       * This is a bit annoying, but we have no choice but to keep them all for now -
-       * means some now unused data may remain in memory, but think we'll have to live with it. */
-      Main *libmain, *libmain_next;
-      Main *newmain = bfd->main;
-      ListBase new_mainlist = {newmain, newmain};
-
-      for (libmain = oldmain->next; libmain; libmain = libmain_next) {
-        libmain_next = libmain->next;
-        /* Note that LIB_INDIRECT does not work with libraries themselves, so we use non-NULL
-         * parent to detect indirect-linked ones. */
-        if (libmain->curlib && (libmain->curlib->parent != NULL)) {
-          BLI_remlink(&old_mainlist, libmain);
-          BLI_addtail(&new_mainlist, libmain);
-        }
-        else {
-#ifdef PRINT_DEBUG
-          printf("Dropped Main for lib: %s\n", libmain->curlib->id.name);
-#endif
-        }
-      }
-      /* In any case, we need to move all lib data-blocks themselves - those are
-       * 'first level data', getting rid of them would imply updating spaces & co
-       * to prevent invalid pointers access. */
-      BLI_movelisttolist(&newmain->libraries, &oldmain->libraries);
-
-      blo_join_main(&new_mainlist);
-    }
-
-#if 0
-    printf("Remaining mains/libs in oldmain: %d\n", BLI_listbase_count(&fd->old_mainlist) - 1);
-#endif
-
     /* That way, libs (aka mains) we did not reuse in new undone/redone state
      * will be cleared together with oldmain... */
     blo_join_main(&old_mainlist);
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index a54085b3036..5550c4ab6c6 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -3917,6 +3917,11 @@ static void write_libraries(WriteData *wd, Main *main)
     if (main->curlib && main->curlib->packedfile) {
       found_one = true;
     }
+    else if (wd->use_memfile) {
+      /* When writing undo step we always write all existing libraries, makes reading undo step
+       * much easier when dealing with purely indirectly used libraries. */
+      found_one = true;
+    }
     else {
       found_one = false;
       while (!found_one && tot--) {



More information about the Bf-blender-cvs mailing list