From 1df6cd67a15235baececea0d75739c68747a725c Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 25 Feb 2021 15:48:28 +0100 Subject: 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. --- source/blender/blenkernel/intern/lib_id_delete.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source/blender/blenkernel/intern') 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. -- cgit v1.2.3