Undo: Clear more ID runtime data on filewrite.

This should help reducing false 'changed' status detection when reading
back a memfile undo step.

Related to T90593 & D12242.
This commit is contained in:
Bastien Montagne 2021-08-19 15:08:13 +02:00
parent 0f49e4832c
commit e648e38887
1 changed files with 11 additions and 0 deletions

View File

@ -1023,12 +1023,23 @@ 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)->us = 0;
((ID *)id_buffer)->icon_id = 0;
/* Those listbase data change every time we add/remove an ID, and also often when
* renaming one (due to re-sorting). This avoids generating a lot of false 'is changed'
* detections between undo steps. */
((ID *)id_buffer)->prev = NULL;
((ID *)id_buffer)->next = NULL;
/* Those runtime pointers should never be set during writing stage, but just in case clear
* them too. */
((ID *)id_buffer)->orig_id = NULL;
((ID *)id_buffer)->newid = NULL;
/* Even though in theory we could be able to preserve this python instance across undo even
* when we need to re-read the ID into its original address, this is currently cleared in
* #direct_link_id_common in `readfile.c` anyway, */
((ID *)id_buffer)->py_instance = NULL;
const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id);
if (id_type->blend_write != NULL) {