Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <bastien@blender.org>2021-03-22 17:06:41 +0300
committerBastien Montagne <bastien@blender.org>2021-03-22 17:10:27 +0300
commite3f2c94d395c08d4ae02cfdc2dd95b5957af1e2b (patch)
tree669e7b6053d1ce9ae57953e30a5a424190447fec
parent56dabfac5cba8d4762579120e6416230af1465d9 (diff)
Fix T86741: Remapping could create doublons of collections in hierarchy.
Code rebuilding/ensuring the sanity of the collection hierarchy was not checking for a same collection being child of the same parent multiple times. This was already prevented to happen in code adding collections to other collections, but not for the remapping case.
-rw-r--r--source/blender/blenkernel/intern/collection.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
index 178a762fd40..ac23f9012a7 100644
--- a/source/blender/blenkernel/intern/collection.c
+++ b/source/blender/blenkernel/intern/collection.c
@@ -1617,18 +1617,23 @@ bool BKE_collection_child_remove(Main *bmain, Collection *parent, Collection *ch
*/
void BKE_collection_parent_relations_rebuild(Collection *collection)
{
- for (CollectionChild *child = collection->children.first, *child_next = NULL; child;
- child = child_next) {
- child_next = child->next;
+ LISTBASE_FOREACH_MUTABLE (CollectionChild *, child, &collection->children) {
+ /* Check for duplicated children (can happen with remapping e.g.). */
+ CollectionChild *other_child = collection_find_child(collection, child->collection);
+ if (other_child != child) {
+ BLI_freelinkN(&collection->children, child);
+ continue;
+ }
+ /* Invalid child, either without a collection, or because it creates a dependency cycle. */
if (child->collection == NULL || BKE_collection_cycle_find(collection, child->collection)) {
BLI_freelinkN(&collection->children, child);
+ continue;
}
- else {
- CollectionParent *cparent = MEM_callocN(sizeof(CollectionParent), __func__);
- cparent->collection = collection;
- BLI_addtail(&child->collection->parents, cparent);
- }
+
+ CollectionParent *cparent = MEM_callocN(sizeof(CollectionParent), __func__);
+ cparent->collection = collection;
+ BLI_addtail(&child->collection->parents, cparent);
}
}