[Bf-blender-cvs] [1df6cd67a15] master: Fix (unreported) bad usercount handling in batch ID deletion.

Bastien Montagne noreply at git.blender.org
Thu Feb 25 17:49:00 CET 2021


Commit: 1df6cd67a15235baececea0d75739c68747a725c
Author: Bastien Montagne
Date:   Thu Feb 25 15:48:28 2021 +0100
Branches: master
https://developer.blender.org/rB1df6cd67a15235baececea0d75739c68747a725c

Fix (unreported) bad usercount handling in batch ID deletion.

This was rather obscure and non-critical issue, but in some cases ID
usercount of some deleted IDs from batch-deletion code would not be
properly nullified, which would then assert later in actual deletion
code.

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

M	source/blender/blenkernel/intern/lib_id_delete.c

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

diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index 8075660dcd1..7c5032c97f4 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -305,13 +305,16 @@ static size_t id_delete(Main *bmain, const bool do_tagged_deletion)
         /* Since we removed ID from Main,
          * we also need to unlink its own other IDs usages ourself. */
         BKE_libblock_relink_ex(bmain, id, NULL, NULL, 0);
-        /* Now we can safely mark that ID as not being in Main database anymore. */
-        id->tag |= LIB_TAG_NO_MAIN;
-        /* This is needed because we may not have remapped usages
-         * of that ID by other deleted ones. */
-        // id->us = 0;  /* Is it actually? */
       }
     }
+
+    /* Now we can safely mark that ID as not being in Main database anymore. */
+    /* NOTE: This needs to be done in a separate loop than above, otherwise some usercounts of
+     * deleted IDs may not be properly decreased by the remappings (since `NO_MAIN` ID usercounts
+     * is never affected). */
+    for (ID *id = tagged_deleted_ids.first; id; id = id->next) {
+      id->tag |= LIB_TAG_NO_MAIN;
+    }
   }
   else {
     /* First tag all datablocks directly from target lib.



More information about the Bf-blender-cvs mailing list