Fix (unreported) broken do_version of hidden layers from pre-2.8 files.

`BKE_collection_object_add` ensures given object is added to an editable
collection, and not e.g. a linked or override one.

However, some processes like do_version manipulate collections also from
libraries, i.e. linked collections, in those cases we need a version of
the code that unconditionnally adds the given object to the given
colleciton.
This commit is contained in:
Bastien Montagne 2022-02-03 15:34:56 +01:00
parent 3bcbbf8992
commit 946c70e6a7
3 changed files with 26 additions and 8 deletions

View File

@ -123,11 +123,20 @@ struct Collection *BKE_collection_object_find(struct Main *bmain,
bool BKE_collection_is_empty(const struct Collection *collection);
/**
* Add object to collection
* Add object to given collection, ensuring this collection is 'editable' (i.e. local and not a
* liboverride), and finding a suitable parent one otherwise.
*/
bool BKE_collection_object_add(struct Main *bmain,
struct Collection *collection,
struct Object *ob);
/**
* Same as #BKE_collection_object_add, but uncondionnaly adds the object to the given collection.
*
* NOTE: required in certain cases, like do-versionning or complex ID management tasks.
*/
bool BKE_collection_object_add_notest(struct Main *bmain,
struct Collection *collection,
struct Object *ob);
/**
* Add \a ob_dst to all scene collections that reference object \a ob_src is in.
* Used for copying objects.

View File

@ -1094,14 +1094,12 @@ static bool collection_object_remove(Main *bmain,
return true;
}
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
bool BKE_collection_object_add_notest(Main *bmain, Collection *collection, Object *ob)
{
if (ELEM(NULL, collection, ob)) {
if (ob == NULL) {
return false;
}
collection = collection_parent_editable_find_recursive(collection);
/* Only case where this pointer can be NULL is when scene itself is linked, this case should
* never be reached. */
BLI_assert(collection != NULL);
@ -1122,6 +1120,17 @@ bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
return true;
}
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
{
if (collection == NULL) {
return false;
}
collection = collection_parent_editable_find_recursive(collection);
return BKE_collection_object_add_notest(bmain, collection, ob);
}
void BKE_collection_object_add_from(Main *bmain, Scene *scene, Object *ob_src, Object *ob_dst)
{
bool is_instantiated = false;

View File

@ -349,7 +349,7 @@ static void do_version_scene_collection_convert(
LISTBASE_FOREACH (LinkData *, link, &sc->objects) {
Object *ob = link->data;
if (ob) {
BKE_collection_object_add(bmain, collection, ob);
BKE_collection_object_add_notest(bmain, collection, ob);
id_us_min(&ob->id);
}
}
@ -459,7 +459,7 @@ static void do_version_layers_to_collections(Main *bmain, Scene *scene)
/* Note usually this would do slow collection syncing for view layers,
* but since no view layers exists yet at this point it's fast. */
BKE_collection_object_add(bmain, collections[layer], base->object);
BKE_collection_object_add_notest(bmain, collections[layer], base->object);
}
if (base->flag & SELECT) {
@ -1235,7 +1235,7 @@ void do_versions_after_linking_280(Main *bmain, ReportList *UNUSED(reports))
(*collection_hidden)->flag |= COLLECTION_HIDE_VIEWPORT | COLLECTION_HIDE_RENDER;
}
BKE_collection_object_add(bmain, *collection_hidden, ob);
BKE_collection_object_add_notest(bmain, *collection_hidden, ob);
BKE_collection_object_remove(bmain, collection, ob, true);
}
}