[Bf-blender-cvs] [d5040d57387] undo-experiments: Undo: Re-use existing IDs from old bmain: do not search by name.
Bastien Montagne
noreply at git.blender.org
Fri Nov 29 10:46:16 CET 2019
Commit: d5040d573871aebe10eb16cf9356c8ef9d845d84
Author: Bastien Montagne
Date: Fri Nov 29 10:41:46 2019 +0100
Branches: undo-experiments
https://developer.blender.org/rBd5040d573871aebe10eb16cf9356c8ef9d845d84
Undo: Re-use existing IDs from old bmain: do not search by name.
This is actually a fairly bad idea, since IDs can be renamed...
Only search by pointer value now, this *should* work in all expected
cases once undo/redo fully reuses unchanged data-blocks.
===================================================================
M source/blender/blenloader/intern/readfile.c
===================================================================
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index d29164425a3..a8358a97732 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -9299,14 +9299,15 @@ static BHead *read_libblock(FileData *fd,
if (fd->are_memchunks_identical && !ELEM(idcode, ID_WM, ID_SCR, ID_WS)) {
BLI_assert(fd->memfile);
- Main *old_main = fd->old_mainlist->first;
- ID *old_id = NULL;
- if ((old_id = BKE_libblock_find_name(old_main, idcode, id->name + 2)) != NULL) {
- /* that would only match for basic undo step, redo and other history navigation cannot
- * guarantee this at all. */
- // BLI_assert(old_id == id_bhead->old);
+
+ /* Find the 'current' existing ID we want to reuse instead of the one we would read from
+ * the undo memfile. */
+ Main *old_bmain = fd->old_mainlist->first;
+ ListBase *old_lb = which_libbase(old_bmain, idcode);
+ BLI_assert(old_lb != NULL);
+ if (BLI_findindex(old_lb, id_bhead->old) != -1) {
MEM_freeN(id);
- id = old_id;
+ id = (ID *)id_bhead->old;
id->tag = tag | LIB_TAG_NEED_LINK | LIB_TAG_NEW;
id->lib = main->curlib;
@@ -9317,9 +9318,8 @@ static BHead *read_libblock(FileData *fd,
oldnewmap_insert(fd->libmap, id_bhead->old, id, id_bhead->code);
- ListBase *old_lb = which_libbase(old_main, idcode);
ListBase *new_lb = which_libbase(main, idcode);
- BLI_remlink_safe(old_lb, id);
+ BLI_remlink(old_lb, id);
BLI_addtail(new_lb, id);
if (r_id) {
More information about the Bf-blender-cvs
mailing list