[Bf-blender-cvs] [e6184cde9ad] undo-experiments: use new 'unique realloc' of ID.

Bastien Montagne noreply at git.blender.org
Fri Feb 21 17:16:12 CET 2020


Commit: e6184cde9adb11575aeb0f342cbfbbef77c8bbca
Author: Bastien Montagne
Date:   Fri Feb 21 17:14:18 2020 +0100
Branches: undo-experiments
https://developer.blender.org/rBe6184cde9adb11575aeb0f342cbfbbef77c8bbca

use new 'unique realloc' of ID.

that way we do not have to stupidly ensure unique addresses of all IDs
read during an undo step, but only for those we actually need.

Combined with the 'almost always reuse old address' feature of undo swap
branch, this should ensure us to almost never call that code in
practice.

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

M	source/blender/blenloader/intern/readfile.c

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index fbb02992a01..bb4432de595 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2301,14 +2301,7 @@ static void *read_struct(FileData *fd, BHead *bh, const char *blockname)
       }
       else {
         /* SDNA_CMP_EQUAL */
-        if (fd->memfile != NULL && !ELEM(bh->code, DATA, GLOB, DNA1, TEST, REND, USER, ENDB)) {
-          Main *bmain = fd->mainlist->first;
-          temp = BKE_main_idmemhash_unique_alloc(
-              bmain, NULL, MEM_mallocN, (size_t)bh->len, blockname);
-        }
-        else {
-          temp = MEM_mallocN(bh->len, blockname);
-        }
+        temp = MEM_mallocN(bh->len, blockname);
 #ifdef USE_BHEAD_READ_ON_DEMAND
         if (BHEADN_FROM_BHEAD(bh)->has_data) {
           memcpy(temp, (bh + 1), bh->len);
@@ -9114,7 +9107,7 @@ static BHead *read_libblock(FileData *fd,
         bool can_finalize_and_return = false;
 
         if (ELEM(idcode, ID_WM, ID_SCR, ID_WS)) {
-          /* Read WindowManager, Screen and WorkSpace IDs are never during undo (see
+          /* Read WindowManager, Screen and WorkSpace IDs are never actually used during undo (see
            * `setup_app_data()` in `blendfile.c`).
            * So we can just abort here, just ensuring libmapping is set accordingly. */
           can_finalize_and_return = true;
@@ -9169,6 +9162,13 @@ static BHead *read_libblock(FileData *fd,
     /* do after read_struct, for dna reconstruct */
     lb = which_libbase(main, idcode);
     if (lb) {
+      /* 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 (!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__);
+      }
+
       /* for ID_LINK_PLACEHOLDER check */
       oldnewmap_insert(fd->libmap, id_bhead->old, id, id_bhead->code);



More information about the Bf-blender-cvs mailing list