[Bf-blender-cvs] [194cc8410bd] master: Fix (unreported) lost ID tags on undo.

Bastien Montagne noreply at git.blender.org
Tue Dec 20 04:48:12 CET 2022


Commit: 194cc8410bd77ccfe24119dcd61468e79641c49c
Author: Bastien Montagne
Date:   Tue Dec 20 12:14:12 2022 +0900
Branches: master
https://developer.blender.org/rB194cc8410bd77ccfe24119dcd61468e79641c49c

Fix (unreported) lost ID tags on undo.

ID tags were fully cleared on file write, however some should be written
so that they are preserved accross undo steps.

Currently this likely did not cause any serious issue, as the missing
ones were not that critical.

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

M	source/blender/blenloader/intern/readfile.cc
M	source/blender/blenloader/intern/writefile.cc
M	source/blender/makesdna/DNA_ID.h

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

diff --git a/source/blender/blenloader/intern/readfile.cc b/source/blender/blenloader/intern/readfile.cc
index d7db103a460..938041368f0 100644
--- a/source/blender/blenloader/intern/readfile.cc
+++ b/source/blender/blenloader/intern/readfile.cc
@@ -2034,7 +2034,7 @@ static void direct_link_id_common(
   id->py_instance = nullptr;
 
   /* Initialize with provided tag. */
-  id->tag = tag;
+  id->tag = tag | (id->tag & LIB_TAG_KEEP_ON_UNDO);
 
   if (ID_IS_LINKED(id)) {
     id->library_weak_reference = nullptr;
@@ -3105,7 +3105,7 @@ static void read_libblock_undo_restore_identical(
   BLI_assert(id_old != nullptr);
 
   /* Some tags need to be preserved here. */
-  id_old->tag = tag | (id_old->tag & LIB_TAG_EXTRAUSER);
+  id_old->tag = tag | (id_old->tag & LIB_TAG_KEEP_ON_UNDO);
   id_old->lib = main->curlib;
   id_old->us = ID_FAKE_USERS(id_old);
   /* Do not reset id->icon_id here, memory allocated for it remains valid. */
diff --git a/source/blender/blenloader/intern/writefile.cc b/source/blender/blenloader/intern/writefile.cc
index bc1a90fb022..7e2840c3379 100644
--- a/source/blender/blenloader/intern/writefile.cc
+++ b/source/blender/blenloader/intern/writefile.cc
@@ -1253,7 +1253,7 @@ static bool write_file_handle(Main *mainvar,
         memcpy(id_buffer, id, idtype_struct_size);
 
         /* Clear runtime data to reduce false detection of changed data in undo/redo context. */
-        ((ID *)id_buffer)->tag = 0;
+        ((ID *)id_buffer)->tag &= LIB_TAG_KEEP_ON_UNDO;
         ((ID *)id_buffer)->us = 0;
         ((ID *)id_buffer)->icon_id = 0;
         /* Those listbase data change every time we add/remove an ID, and also often when
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 3feb341b773..fb23dd8644a 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -848,6 +848,15 @@ enum {
   LIB_TAG_LIB_OVERRIDE_NEED_RESYNC = 1 << 21,
 };
 
+/**
+ * Most of ID tags are cleared on file write (i.e. also when storing undo steps), since they
+ * either have of very short lifetime (not expected to exist accross undo steps), or are info that
+ * will be re-generated when reading undo steps.
+ *
+ * However a few of these need to be explicitely preserved accross undo steps.
+ */
+#define LIB_TAG_KEEP_ON_UNDO (LIB_TAG_EXTRAUSER | LIB_TAG_MISSING)
+
 /* Tag given ID for an update in all the dependency graphs. */
 typedef enum IDRecalcFlag {
   /***************************************************************************



More information about the Bf-blender-cvs mailing list