[Bf-blender-cvs] [29e2ca5d535] undo-experiments-swap-reread-datablocks: Reset to current undo-experiments branch.

Bastien Montagne noreply at git.blender.org
Sun Jan 26 21:08:10 CET 2020


Commit: 29e2ca5d5353450ad325eabe1b4bfc42e2169c8d
Author: Bastien Montagne
Date:   Sun Jan 26 21:07:55 2020 +0100
Branches: undo-experiments-swap-reread-datablocks
https://developer.blender.org/rB29e2ca5d5353450ad325eabe1b4bfc42e2169c8d

Reset to current undo-experiments branch.

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

M	source/blender/blenkernel/BKE_blender_undo.h
M	source/blender/blenkernel/BKE_main.h
M	source/blender/blenkernel/BKE_undo_system.h
M	source/blender/blenkernel/intern/blender_undo.c
M	source/blender/blenkernel/intern/blendfile.c
M	source/blender/blenkernel/intern/library.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/undo_system.c
M	source/blender/blenloader/BLO_readfile.h
M	source/blender/blenloader/BLO_undofile.h
M	source/blender/blenloader/intern/readblenentry.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/readfile.h
M	source/blender/blenloader/intern/undofile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/undo/memfile_undo.c
M	source/blender/makesdna/DNA_ID.h

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

diff --git a/source/blender/blenkernel/BKE_blender_undo.h b/source/blender/blenkernel/BKE_blender_undo.h
index 7392d3947a2..4ecedbbfc1e 100644
--- a/source/blender/blenkernel/BKE_blender_undo.h
+++ b/source/blender/blenkernel/BKE_blender_undo.h
@@ -32,7 +32,10 @@ struct bContext;
 
 struct MemFileUndoData *BKE_memfile_undo_encode(struct Main *bmain,
                                                 struct MemFileUndoData *mfu_prev);
-bool BKE_memfile_undo_decode(struct MemFileUndoData *mfu, struct bContext *C);
+bool BKE_memfile_undo_decode(struct MemFileUndoData *mfu,
+                             const int undo_direction,
+                             const bool use_old_bmain_data,
+                             struct bContext *C);
 void BKE_memfile_undo_free(struct MemFileUndoData *mfu);
 
 #ifdef __cplusplus
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index c48a9cad443..c756a5e12df 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -85,6 +85,11 @@ typedef struct Main {
    * use "needs_flush_to_id" in edit data to flag data which needs updating.
    */
   char is_memfile_undo_flush_needed;
+  /**
+   * Indicates that next memfile undo step should not allow to re-use old bmain when re-read, but
+   * instead do a complete full re-read/update from stored memfile.
+   */
+  char use_memfile_full_barrier;
 
   BlendThumbnail *blen_thumb;
 
diff --git a/source/blender/blenkernel/BKE_undo_system.h b/source/blender/blenkernel/BKE_undo_system.h
index bc10d422a61..74ce4d3f020 100644
--- a/source/blender/blenkernel/BKE_undo_system.h
+++ b/source/blender/blenkernel/BKE_undo_system.h
@@ -79,6 +79,9 @@ typedef struct UndoStep {
   bool skip;
   /** Some situations require the global state to be stored, edge cases when exiting modes. */
   bool use_memfile_step;
+  /** When this is true, undo/memfile read code is allowed to re-use old data-blocks for unchanged
+   * IDs, and existing depsgraphes. This has to be forbidden in some cases (like renamed IDs). */
+  bool use_old_bmain_data;
   /** For use by undo systems that accumulate changes (text editor, painting). */
   bool is_applied;
   /* Over alloc 'type->struct_size'. */
diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c
index cd950e05415..83c39e81ff3 100644
--- a/source/blender/blenkernel/intern/blender_undo.c
+++ b/source/blender/blenkernel/intern/blender_undo.c
@@ -61,7 +61,7 @@
 
 #define UNDO_DISK 0
 
-bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C)
+bool BKE_memfile_undo_decode(MemFileUndoData *mfu, const int undo_direction, const bool use_old_bmain_data, bContext *C)
 {
   Main *bmain = CTX_data_main(C);
   char mainstr[sizeof(bmain->name)];
@@ -76,8 +76,12 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C)
     success = BKE_blendfile_read(C, mfu->filename, &(const struct BlendFileReadParams){0}, NULL);
   }
   else {
-    success = BKE_blendfile_read_from_memfile(
-        C, &mfu->memfile, &(const struct BlendFileReadParams){0}, NULL);
+    struct BlendFileReadParams params = {0};
+    params.undo_direction = undo_direction > 0 ? 1 : -1;
+    if (!use_old_bmain_data) {
+      params.skip_flags |= BLO_READ_SKIP_UNDO_OLD_MAIN;
+    }
+    success = BKE_blendfile_read_from_memfile(C, &mfu->memfile, &params, NULL);
   }
 
   /* Restore, bmain has been re-allocated. */
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index 62173393256..6c48104662c 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -473,8 +473,7 @@ bool BKE_blendfile_read_from_memfile(bContext *C,
   Main *bmain = CTX_data_main(C);
   BlendFileData *bfd;
 
-  bfd = BLO_read_from_memfile(
-      bmain, BKE_main_blendfile_path(bmain), memfile, params->skip_flags, reports);
+  bfd = BLO_read_from_memfile(bmain, BKE_main_blendfile_path(bmain), memfile, params, reports);
   if (bfd) {
     /* remove the unused screens and wm */
     while (bfd->main->wm.first) {
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index a00611d51a0..49faeb7aa0d 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -802,7 +802,6 @@ bool BKE_id_copy(Main *bmain, const ID *id, ID **newid)
 /**
  * Does a mere memory swap over the whole IDs data (including type-specific memory).
  * \note Most internal ID data itself is not swapped (only IDProperties are).
- * \note bmain may be NULL, in which case no internal pointers to itself remapping will be done.
  */
 void BKE_id_swap(Main *bmain, ID *id_a, ID *id_b)
 {
@@ -866,11 +865,9 @@ void BKE_id_swap(Main *bmain, ID *id_a, ID *id_b)
   id_a->properties = id_b_back.properties;
   id_b->properties = id_a_back.properties;
 
-  if (bmain != NULL) {
-    /* Swap will have broken internal references to itself, restore them. */
-    BKE_libblock_relink_ex(bmain, id_a, id_b, id_a, ID_REMAP_SKIP_NEVER_NULL_USAGE);
-    BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, ID_REMAP_SKIP_NEVER_NULL_USAGE);
-  }
+  /* Swap will have broken internal references to itself, restore them. */
+  BKE_libblock_relink_ex(bmain, id_a, id_b, id_a, ID_REMAP_SKIP_NEVER_NULL_USAGE);
+  BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, ID_REMAP_SKIP_NEVER_NULL_USAGE);
 }
 
 /** Does *not* set ID->newid pointer. */
@@ -2432,6 +2429,9 @@ void BLI_libblock_ensure_unique_name(Main *bmain, const char *name)
     BKE_id_new_name_validate(lb, idtest, NULL);
     bmain->is_memfile_undo_written = false;
   }
+
+  /* ID renaming requires an 'undo barrier'. */
+  bmain->use_memfile_full_barrier = true;
 }
 
 /**
@@ -2443,6 +2443,9 @@ void BKE_libblock_rename(Main *bmain, ID *id, const char *name)
   if (BKE_id_new_name_validate(lb, id, name)) {
     bmain->is_memfile_undo_written = false;
   }
+
+  /* ID renaming requires an 'undo barrier'. */
+  bmain->use_memfile_full_barrier = true;
 }
 
 /**
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 13ed3557005..8c734ee4767 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -2155,6 +2155,11 @@ GHash *BKE_scene_undo_depsgraphs_extract(Main *bmain)
       BLI_ghashutil_strhash_p, BLI_ghashutil_strcmp, __func__);
 
   for (Scene *scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) {
+    if (scene->depsgraph_hash == NULL) {
+      /* In some cases, e.g. when undo has to perform multiple steps at once, no depsgraph will be
+       * built so this pointer may be NULL. */
+      continue;
+    }
     for (ViewLayer *view_layer = scene->view_layers.first; view_layer != NULL;
          view_layer = view_layer->next) {
       DepsgraphKey key;
@@ -2195,6 +2200,11 @@ void BKE_scene_undo_depsgraphs_restore(Main *bmain, GHash *depsgraph_extract)
 
       Depsgraph **depsgraph_extract_ptr = (Depsgraph **)BLI_ghash_lookup_p(depsgraph_extract,
                                                                            key_full);
+      if (depsgraph_extract_ptr == NULL) {
+        continue;
+      }
+      BLI_assert(*depsgraph_extract_ptr != NULL);
+
       Depsgraph **depsgraph_scene_ptr = scene_get_depsgraph_p(
           bmain, scene, view_layer, true, false);
       BLI_assert(depsgraph_scene_ptr != NULL);
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index eee07437aa7..a97aa75cf54 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -26,9 +26,7 @@
 
 #include "BLI_utildefines.h"
 #include "BLI_sys_types.h"
-#include "BLI_ghash.h"
 #include "BLI_listbase.h"
-#include "BLI_path_util.h"
 #include "BLI_string.h"
 
 #include "BLT_translation.h"
@@ -40,7 +38,6 @@
 #include "BKE_global.h"
 #include "BKE_library_override.h"
 #include "BKE_main.h"
-#include "BKE_scene.h"
 #include "BKE_undo_system.h"
 
 #include "MEM_guardedalloc.h"
@@ -166,6 +163,7 @@ static bool undosys_step_encode(bContext *C, Main *bmain, UndoStack *ustack, Und
        * not all members are filled in. */
       us->type->step_foreach_ID_ref(us, undosys_id_ref_store, bmain);
     }
+
 #ifdef WITH_GLOBAL_UNDO_CORRECT_ORDER
     if (us->type == BKE_UNDOSYS_TYPE_MEMFILE) {
       ustack->step_active_memfile = us;
@@ -192,15 +190,11 @@ static void undosys_step_decode(
             /* Common case, we're already using the last memfile state. */
           }
           else {
-            GHash *depsgraphs = BKE_scene_undo_depsgraphs_extract(bmain);
-
             /* Load the previous memfile state so any ID's referenced in this
              * undo step will be correctly resolved, see: T56163. */
             undosys_step_decode(C, bmain, ustack, us_iter, dir, false);
             /* May have been freed on memfile read. */
             bmain = G_MAIN;
-
-            BKE_scene_undo_depsgraphs_restore(bmain, depsgraphs);
           }
           break;
         }
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index adf3bf00d48..3c6f6298bb8 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -74,8 +74,11 @@ typedef struct WorkspaceConfigFileData {
 } WorkspaceConfigFileData;
 
 struct BlendFileReadParams {
-  uint skip_flags : 2; /* eBLOReadSkip */
+  uint skip_flags : 3; /* eBLOReadSkip */
   uint is_startup : 1;
+
+  /** Whether we are reading the memfile for an undo (< 0) or a redo (> 0). */
+  int undo_direction : 2;
 };
 
 /* skip reading some data-block types (may want to skip screen data too). */
@@ -83,6 +86,8 @@ typedef enum eBLOReadSkip {
   BLO_READ_SKIP_NONE = 0,
   BLO_READ_SKIP_USERDEF = (1 << 0),
   BLO_READ_SKIP_DATA = (1 << 1),
+  /** Do not attempt to re-use IDs from old bmain for unchanged ones in case of undo. */
+  BLO_READ_SKIP_UNDO_OLD_MAIN = (1 << 2),
 } eBLOReadSkip;
 #define BLO_READ_SKIP_ALL (BLO_READ_SKIP_USERDEF | BLO_READ_SKIP_DATA)
 
@@ -96,7 +101,7 @@ BlendFileData *BLO_read_from_memory(const void 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list