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

Bastien Montagne noreply at git.blender.org
Thu Jan 30 12:36:29 CET 2020


Commit: 09e59f100d0e6637390b6ac543d2aef1c5458595
Author: Bastien Montagne
Date:   Thu Jan 30 12:36:03 2020 +0100
Branches: undo-experiments-swap-reread-datablocks
https://developer.blender.org/rB09e59f100d0e6637390b6ac543d2aef1c5458595

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

Conflicts:
	source/blender/blenloader/intern/readfile.c

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



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

diff --cc source/blender/blenloader/intern/readfile.c
index a5c08caadf9,ab293343886..b8f36b05c19
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@@ -9447,14 -9447,13 +9447,16 @@@ static BHead *read_libblock(FileData *f
    /* read libblock */
    fd->are_memchunks_identical = true;
    id = read_struct(fd, bhead, "lib block");
 +  const short idcode = id != NULL ? GS(id->name) : 0;
  
    BHead *id_bhead = bhead;
 +  /* Used when undoing from memfile, we swap changed IDs into their old addresses when found. */
 +  ID *id_old = NULL;
 +  bool do_id_swap = false;
  
    if (id != NULL) {
 -    const short idcode = GS(id->name);
+     const bool do_partial_undo = (fd->skip_flags & BLO_READ_SKIP_UNDO_OLD_MAIN) == 0;
+ 
      if (id_bhead->code != ID_LINK_PLACEHOLDER) {
        /* need a name for the mallocN, just for debugging and sane prints on leaks */
        allocname = dataname(idcode);
@@@ -9475,7 -9474,9 +9477,9 @@@
  
          /* Find the 'current' existing ID we want to reuse instead of the one we would read from
           * the undo memfile. */
-         id_old = BKE_main_idmap_lookup(fd->old_idmap, idcode, id->name + 2, NULL);
 -        ID *id_old = do_partial_undo ?
 -                         BKE_main_idmap_lookup(fd->old_idmap, idcode, id->name + 2, NULL) :
 -                         NULL;
++        id_old = do_partial_undo ?
++                     BKE_main_idmap_lookup(fd->old_idmap, idcode, id->name + 2, NULL) :
++                     NULL;
          bool can_finalize_and_return = false;
  
          if (ELEM(idcode, ID_WM, ID_SCR, ID_WS)) {
@@@ -9534,24 -9530,16 +9537,23 @@@
      /* do after read_struct, for dna reconstruct */
      lb = which_libbase(main, idcode);
      if (lb) {
 -      /* for ID_LINK_PLACEHOLDER check */
 -      oldnewmap_insert(fd->libmap, id_bhead->old, id, id_bhead->code);
 -
        /* 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 && (fd->skip_flags & BLO_READ_SKIP_UNDO_OLD_MAIN) == 0 &&
-           id->lib == NULL) {
+       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) {
 +          id_old = BKE_main_idmap_lookup(fd->old_idmap, idcode, id->name + 2, 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);
 +          oldnewmap_insert(
 +              fd->libmap_undo_reused, id_old, do_id_swap ? id_old : id, id_bhead->code);
          }
        }



More information about the Bf-blender-cvs mailing list