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.
This commit is contained in:
Bastien Montagne 2022-12-20 12:14:12 +09:00
parent c2a8d8b18d
commit 194cc8410b
3 changed files with 12 additions and 3 deletions

View File

@ -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. */

View File

@ -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

View File

@ -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 {
/***************************************************************************