Fix (unreported) crash when deleting ObData while keeping their ShapeKeys.

Batch deletion of IDs could lead to deleting ObData ones while keeping
the related ShapeKeys.

Orphaned shape keys are not allowed anymore in Blender, they are checked
against in both file write and read code.

This would lead to assert (and crash) e.g. in the liboverride code.

This commit forcefully add shapekeys of deleted meshes, curves etc.,
when calling e.g. `BKE_id_multi_tagged_delete`.

Note that deleting the shapekey when deleting the obdata ID was already
implemented in single ID deletion (`BKE_id_delete` & co), in the
underlying private `id_free`. But this is skipped in `no main` case.
which is used by the batch deletion code for performance optimizations.
This commit is contained in:
Bastien Montagne
2023-09-06 18:00:33 +02:00
parent fc02d5ee11
commit eadc54bb5d

View File

@@ -273,6 +273,19 @@ static size_t id_delete(Main *bmain,
* code has some specific handling of 'no main' IDs that would be a problem in that
* case). */
id->tag |= tag;
/* Forcefully also delete shapekeys of the deleted ID if any, 'orphaned' shapekeys are
* not allowed in Blender and will cause lots of problem in modern code (liboverrides,
* warning on write & read, etc.). */
Key *shape_key = BKE_key_from_id(id);
if (shape_key && (shape_key->id.tag & tag) == 0) {
BLI_remlink(&bmain->shapekeys, &shape_key->id);
BKE_main_namemap_remove_name(bmain, &shape_key->id, shape_key->id.name + 2);
BLI_addtail(&tagged_deleted_ids, &shape_key->id);
BKE_id_remapper_add(id_remapper, &shape_key->id, nullptr);
shape_key->id.tag |= tag;
}
keep_looping = true;
}
}