[Bf-blender-cvs] [77dcf71d34c] uuid-undo-experiments-swap-reread-datablocks: Merge branch 'uuid-undo-experiments' into uuid-undo-experiments-swap-reread-datablocks

Bastien Montagne noreply at git.blender.org
Fri Feb 28 15:46:41 CET 2020


Commit: 77dcf71d34ca047a364c5569ed6d5af4d1b4b383
Author: Bastien Montagne
Date:   Fri Feb 28 15:43:38 2020 +0100
Branches: uuid-undo-experiments-swap-reread-datablocks
https://developer.blender.org/rB77dcf71d34ca047a364c5569ed6d5af4d1b4b383

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

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



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

diff --cc source/blender/blenloader/intern/readfile.c
index 5a77ff31f23,97072310e57..85bb5850105
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@@ -9117,22 -9084,15 +9106,20 @@@ static BHead *read_libblock(FileData *f
            "%s: ID %s is unchanged: %d\n", __func__, id->name, fd->are_memchunks_identical);
  
        if (fd->memfile != NULL) {
 -        BLI_assert(fd->old_idmap != NULL || !do_partial_undo);
 +        BLI_assert(fd->old_valid_ids != NULL || !do_partial_undo);
          /* This code should only ever be reached for local data-blocks. */
          BLI_assert(main->curlib == NULL);
-         BLI_assert(main->used_id_memhash != NULL &&
-                    main->used_id_memhash == ((Main *)fd->old_mainlist->first)->used_id_memhash);
  
          /* Find the 'current' existing ID we want to reuse instead of the one we would read from
           * the undo memfile. */
 -        ID *id_old = do_partial_undo ?
 -                         BKE_main_idmap_lookup(fd->old_idmap, idcode, id->name + 2, NULL) :
 -                         NULL;
 +        if (do_partial_undo) {
-           id_old_memh = id_old = BKE_main_idmemhash_lookup_id(main, id_bhead->old, &used_id_chain);
++          id_old_memh = id_old = id_bhead->old;
 +          if (!BLI_gset_haskey(fd->old_valid_ids, id_old)) {
 +            DEBUG_PRINTF("Found an old, invalid id_old pointer for new %s\n", id->name);
 +            id_old = NULL;
 +            used_id_chain = NULL;
 +          }
 +        }
          bool can_finalize_and_return = false;
  
          if (ELEM(idcode, ID_WM, ID_SCR, ID_WS)) {
@@@ -9198,47 -9148,16 +9179,42 @@@
        /* Some re-used old IDs might also use newly read ones, so we have to check for old memory
         * 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);
 +        BLI_assert(fd->old_valid_ids != NULL);
 +        if (id_old == NULL) {
-           id_old_memh = id_old = BKE_main_idmemhash_lookup_id(main, id_bhead->old, &used_id_chain);
++          id_old_memh = id_old = id_bhead->old;
 +          if (!BLI_gset_haskey(fd->old_valid_ids, 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);
-         /* Note that even if id_old_memh is not valid enymore (i.e. we cannot actually re-use that
-          * old ID), we still want to pass it here, to keep history chain consistent. */
-         if (!BKE_main_idmemhash_register_id(main, id_old_memh, id)) {
-           id = BKE_main_idmemhash_unique_realloc(main, id_old_memh, 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);
      }
      else {



More information about the Bf-blender-cvs mailing list