[Bf-blender-cvs] [5a27d05424a] undo-experiments-idnames: undoexp: refine handling of 'undo barrier'.

Bastien Montagne noreply at git.blender.org
Thu Jan 9 11:26:02 CET 2020


Commit: 5a27d05424aa490cbc94c6e88ff29b68bc57bb22
Author: Bastien Montagne
Date:   Thu Jan 9 11:19:56 2020 +0100
Branches: undo-experiments-idnames
https://developer.blender.org/rB5a27d05424aa490cbc94c6e88ff29b68bc57bb22

undoexp: refine handling of 'undo barrier'.

This also fixes the mesh keeping its edited shape when undoing out of
edit mode e.g.

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

M	source/blender/editors/undo/memfile_undo.c

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

diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c
index ff2e304a9f4..2f1a9a6c8f7 100644
--- a/source/blender/editors/undo/memfile_undo.c
+++ b/source/blender/editors/undo/memfile_undo.c
@@ -120,20 +120,55 @@ static int memfile_undosys_step_id_reused_cb(void *user_data,
 }
 
 static void memfile_undosys_step_decode(
-    struct bContext *C, struct Main *bmain, UndoStep *us_p, int UNUSED(dir), bool UNUSED(is_final))
+    struct bContext *C, struct Main *bmain, UndoStep *us_p, int dir, bool UNUSED(is_final))
 {
   MemFileUndoStep *us = (MemFileUndoStep *)us_p;
 
+  bool use_old_bmain_data = true;
+
+  if (dir > 0) {
+    /* Redo case.
+     * The only time we should have to force a complete redo is when current step is tagged as a
+     * redo barrier.
+     * If previous step was not a memfile one should not matter here, current data in old bmain
+     * should still always be valid for unchanged dtat-blocks. */
+    if (us->step.use_old_bmain_data == false) {
+      use_old_bmain_data = false;
+    }
+  }
+  else {
+    /* Undo case.
+     * Here we do not care whether current step is an undo barrier, since we are comming from 'the
+     * future' we can still re-use old data. However, if *next* undo step (i.e. the one immédiately
+     * in the future, the one we are comming from) is a barrier, then we have to force a complete
+     * undo.
+     * Likewise, if next step (the one we are comming from) was a non-memfile one, there is no
+     * guarantee that current bmain data actually reflects the status of unchanged datablocks in
+     * memfile, since changes might have been flushed to current bmain data without triggering any
+     * memfile step storage (typical common case e.g. when using edit modes).
+     */
+    BLI_assert(dir < 0);
+    UndoStep *us_next = us_p->next;
+    if (us_next != NULL) {
+      if (us_next->use_old_bmain_data == false) {
+        use_old_bmain_data = false;
+      }
+      if (us_next->type != BKE_UNDOSYS_TYPE_MEMFILE) {
+        use_old_bmain_data = false;
+      }
+    }
+  }
+
   /* Extract depsgraphs from current bmain (which may be freed during undo step reading),
    * and store them for re-use. */
   GHash *depsgraphs = NULL;
-  if (us->step.use_old_bmain_data) {
+  if (use_old_bmain_data) {
     depsgraphs = BKE_scene_undo_depsgraphs_extract(bmain);
   }
 
   ED_editors_exit(bmain, false);
 
-  BKE_memfile_undo_decode(us->data, us->step.use_old_bmain_data, C);
+  BKE_memfile_undo_decode(us->data, use_old_bmain_data, C);
 
   for (UndoStep *us_iter = us_p->next; us_iter; us_iter = us_iter->next) {
     if (BKE_UNDOSYS_TYPE_IS_MEMFILE_SKIP(us_iter->type)) {
@@ -152,7 +187,7 @@ static void memfile_undosys_step_decode(
   bmain = CTX_data_main(C);
   ED_editors_init_for_undo(bmain);
 
-  if (us->step.use_old_bmain_data) {
+  if (use_old_bmain_data) {
     /* Restore previous depsgraphs into current bmain. */
     BKE_scene_undo_depsgraphs_restore(bmain, depsgraphs);



More information about the Bf-blender-cvs mailing list