Fix T101903: Crash when deleting library in some cases.

Remapping in batch deletion could end up calling viewlayer resync code
on partially invalid BMain (some IDs still in Main using IDs removed
from Main).

Think this code can actually be further optimized, but this fix should
be safe enough for 3.3 (and potentially 2.93).

Thanks to Jeroen (@jbakker) for the initial investigation.
This commit is contained in:
Bastien Montagne 2022-10-19 09:18:47 +02:00
parent 4163c63def
commit a450a2f2b2
Notes: blender-bot 2023-10-18 15:23:11 +02:00
Referenced by issue #88449: Blender LTS: Maintenance Task 2.93
Referenced by issue #88449, Blender LTS: Maintenance Task 2.93
Referenced by issue #100749, Blender LTS: Maintenance Task 3.3
Referenced by issue #101903, Overrides: Crash when removing unexisting library (heist scene)
1 changed files with 5 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include "BKE_idprop.h"
#include "BKE_idtype.h"
#include "BKE_key.h"
#include "BKE_layer.h"
#include "BKE_lib_id.h"
#include "BKE_lib_override.h"
#include "BKE_lib_remap.h"
@ -217,6 +218,7 @@ static size_t id_delete(Main *bmain, const bool do_tagged_deletion)
BKE_main_lock(bmain);
if (do_tagged_deletion) {
BKE_layer_collection_resync_forbid();
/* Main idea of batch deletion is to remove all IDs to be deleted from Main database.
* This means that we won't have to loop over all deleted IDs to remove usages
* of other deleted IDs.
@ -279,6 +281,9 @@ static size_t id_delete(Main *bmain, const bool do_tagged_deletion)
}
}
BKE_layer_collection_resync_allow();
BKE_main_collection_sync_remap(bmain);
/* 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 user-counts of
* deleted IDs may not be properly decreased by the remappings (since `NO_MAIN` ID user-counts