Fix T62706: Orphan Data : I have now to save a file, close and reopen it, only then I can purge previous deleted meshes.

libquery code has some specific handling for IDs tagged as 'no_main',
among which to never consider them as refcounted/refcounting other IDs.

This is fine, but it also means we have to be careful when moving an ID
from main to out-of-main status, to do all id remapping we need
//before// we tag it as no_main.

That was a bit tedious to track down, we'll have to be careful that all
the corner cases we have to take care of, do not end up in a giant soup
of expections to exceptions, where nobody can find its way anymore...
This commit is contained in:
Bastien Montagne 2019-03-18 16:48:31 +01:00
parent d1f04658d8
commit 91ffd39e77
Notes: blender-bot 2023-04-19 22:54:54 +02:00
Referenced by issue #62706, Orphan Data : I have now to save a file, close and reopen it, only then I can purge previous deleted meshes
1 changed files with 5 additions and 1 deletions

View File

@ -1001,7 +1001,9 @@ static void id_delete(Main *bmain, const bool do_tagged_deletion)
if ((id->tag & tag) || (id->lib != NULL && (id->lib->id.tag & tag))) {
BLI_remlink(lb, id);
BLI_addtail(&tagged_deleted_ids, id);
id->tag |= tag | LIB_TAG_NO_MAIN;
/* Do not tag as no_main now, we want to unlink it first (lower-level ID management code
* has some specific handling of 'nom main' IDs that would be a problem in that case). */
id->tag |= tag;
keep_looping = true;
}
}
@ -1021,6 +1023,8 @@ static void id_delete(Main *bmain, const bool do_tagged_deletion)
ID_REMAP_FLAG_NEVER_NULL_USAGE | ID_REMAP_FORCE_NEVER_NULL_USAGE);
/* 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, true);
/* 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? */
}