[Bf-blender-cvs] [e38ab3c7e62] undo-experiments: undoexp: fix bug/crash in recent refactor of WM/SCR/WS IDs handling.

Bastien Montagne noreply at git.blender.org
Thu Jan 30 12:32:58 CET 2020


Commit: e38ab3c7e62adefcd90e50f05f8458c360e34804
Author: Bastien Montagne
Date:   Thu Jan 30 12:27:29 2020 +0100
Branches: undo-experiments
https://developer.blender.org/rBe38ab3c7e62adefcd90e50f05f8458c360e34804

undoexp: fix bug/crash in recent refactor of WM/SCR/WS IDs handling.

Mismatch when partial undo was not enabled.

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

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

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

diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index cffba0207cd..ab293343886 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -9452,6 +9452,7 @@ static BHead *read_libblock(FileData *fd,
 
   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 */
@@ -9467,13 +9468,15 @@ static BHead *read_libblock(FileData *fd,
           "%s: ID %s is unchanged: %d\n", __func__, id->name, fd->are_memchunks_identical);
 
       if (fd->memfile != NULL) {
-        BLI_assert(fd->old_idmap != NULL);
+        BLI_assert(fd->old_idmap != NULL || !do_partial_undo);
         /* This code should only ever be reached for local data-blocks. */
         BLI_assert(main->curlib == NULL);
 
         /* Find the 'current' existing ID we want to reuse instead of the one we would read from
          * the undo memfile. */
-        ID *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;
         bool can_finalize_and_return = false;
 
         if (ELEM(idcode, ID_WM, ID_SCR, ID_WS)) {
@@ -9482,8 +9485,7 @@ static BHead *read_libblock(FileData *fd,
            * So we can just abort here, just ensuring libmapping is set accordingly. */
           can_finalize_and_return = true;
         }
-        else if ((fd->skip_flags & BLO_READ_SKIP_UNDO_OLD_MAIN) == 0 &&
-                 fd->are_memchunks_identical && id_old != NULL) {
+        else if (id_old != NULL && fd->are_memchunks_identical) {
           MEM_freeN(id);
 
           /* Do not add LIB_TAG_NEW here, this should not be needed/used in undo case anyway (as
@@ -9533,8 +9535,7 @@ static BHead *read_libblock(FileData *fd,
 
       /* 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) {



More information about the Bf-blender-cvs mailing list