[Bf-blender-cvs] [1ef2c5f2d00] undo-experiments-swap-reread-datablocks: Merge branch 'undo-experiments' into undo-experiments-swap-reread-datablocks

Bastien Montagne noreply at git.blender.org
Wed Feb 26 12:59:45 CET 2020


Commit: 1ef2c5f2d005674be358553ac30a3626b99b2b6c
Author: Bastien Montagne
Date:   Wed Feb 26 12:42:42 2020 +0100
Branches: undo-experiments-swap-reread-datablocks
https://developer.blender.org/rB1ef2c5f2d005674be358553ac30a3626b99b2b6c

Merge branch 'undo-experiments' into undo-experiments-swap-reread-datablocks

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



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

diff --cc source/blender/blenloader/intern/readfile.c
index ad11e27507f,3970f4df4ef..e34457d4415
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@@ -9193,46 -9175,11 +9193,45 @@@ static BHead *read_libblock(FileData *f
         * addresses for those as well. */
        if (fd->memfile != NULL && do_partial_undo && id->lib == NULL) {
          BLI_assert(fd->old_idmap != NULL);
 -        ID *id_old = BKE_main_idmap_lookup(fd->old_idmap, idcode, id->name + 2, NULL);
 +        if (id_old == NULL) {
 +          LinkNode *used_id_chain_hook = BLI_ghash_lookup(main->used_id_memhash, id_bhead->old);
 +          used_id_chain = used_id_chain_hook ? used_id_chain_hook->link : NULL;
 +          id_old = used_id_chain != NULL ? used_id_chain->link : id_bhead->old;
 +          if (!BKE_main_idmap_lookup_id(fd->old_idmap, id_old)) {
 +            DEBUG_PRINTF("Found an old, invalid id_old pointer for new %s\n", id->name);
 +            id_old = NULL;
 +            used_id_chain = NULL;
 +          }
 +        }
          if (id_old != NULL) {
 -          oldnewmap_insert(fd->libmap_undo_reused, id_old, id, id_bhead->code);
 +          BLI_assert(MEM_allocN_len(id) == MEM_allocN_len(id_old));
 +          /* UI IDs are always re-used from old bmain at higher-level calling code, so never swap
 +           * those. Besides maybe custom properties, no other ID should have pointers to those
 +           * anyway...
 +           * And linked IDs are handled separately as well. */
 +          do_id_swap = !ELEM(idcode, ID_WM, ID_SCR, ID_WS) &&
 +                       !(id_bhead->code == ID_LINK_PLACEHOLDER);
 +        }
 +      }
 +
 +      /* At this point, we know we are going to keep that newly read & allocated ID, so we need to
 +       * reallocate it to ensure we actually get a unique memory address for it. */
 +      if (!do_id_swap) {
 +        DEBUG_PRINTF("using newly-read ID %s to a new mem address\n", id->name);
 +        if (!BKE_main_idmemhash_register_id(main, NULL, id)) {
-           id = BKE_main_idmemhash_unique_realloc(
-               main, NULL, id, MEM_reallocN_id, MEM_allocN_len(id), __func__);
++          id = BKE_main_idmemhash_unique_realloc(main, NULL, id);
          }
        }
 +      else {
 +        DEBUG_PRINTF("using newly-read ID %s to its old, already existing address\n", id->name);
 +      }
 +
 +      /* for ID_LINK_PLACEHOLDER check */
 +      ID *id_target = do_id_swap ? id_old : id;
 +      oldnewmap_insert(fd->libmap, id_bhead->old, id_target, id_bhead->code);
 +      for (; used_id_chain; used_id_chain = used_id_chain->next) {
 +        oldnewmap_insert(fd->libmap, used_id_chain->link, id_target, id_bhead->code);
 +      }
  
        BLI_addtail(lb, id);
      }



More information about the Bf-blender-cvs mailing list