Commit: d0a482d676b31a9ca163bf653309a78bb716e4c1
Author: Bastien Montagne
Date:   Tue Feb 11 11:54:09 2020 +0100
Branches: undo-experiments-swap-reread-datablocks
https://developer.blender.org/rBd0a482d676b31a9ca163bf653309a78bb716e4c1

undoexp: do not liblink re-used datablocks anymore.

Since all existing IDs are supposed to use their same memory address,
unchanged data-blocks should not have any changed pointer to other IDs,
so no need to liblink them at all.

Note that am not 100% sure that is fully valid currently, as we use ID
names to find old IDs, which is not 100% safe and secure solution...

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

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

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

diff --git a/source/blender/blenloader/intern/readfile.c 
b/source/blender/blenloader/intern/readfile.c
index 404942fe139..f183b089618 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -9580,6 +9580,8 @@ static void do_versions_after_linking(Main *main, 
ReportList *reports)
 
 static void lib_link_all(FileData *fd, Main *bmain)
 {
+  const bool do_partial_undo = (fd->skip_flags & BLO_READ_SKIP_UNDO_OLD_MAIN) 
== 0;
+
   ID *id;
   FOREACH_MAIN_ID_BEGIN (bmain, id) {
     if ((id->tag & LIB_TAG_NEED_LINK) == 0) {
@@ -9593,6 +9595,16 @@ static void lib_link_all(FileData *fd, Main *bmain)
       continue;
     }
 
+    if (fd->memfile != NULL && do_partial_undo && (id->tag & 
LIB_TAG_UNDO_OLD_ID_REUSED) != 0) {
+      /* This ID has been re-used from 'old' bmain. Since it was therfore 
unchanged accross current
+       * undo step, and old IDs re-use their old memory address, we do not 
need to liblink it at
+       * all.
+       * NOTE: this is a risky bet that will need a lot of validation. 
Especiqlly as long as we use
+       * idnames to find back IDs accross undo/redo, there //may// be some 
specific situations that
+       * could lead us to using freed memory... */
+      continue;
+    }
+
     lib_link_id(fd, bmain, id);
 
     /* Note: ID types are processed in reverse order as defined by 
INDEX_ID_XXX enums in DNA_ID.h.

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

Reply via email to