diff options
Diffstat (limited to 'source/blender/blenkernel/intern/blendfile_link_append.c')
-rw-r--r-- | source/blender/blenkernel/intern/blendfile_link_append.c | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/source/blender/blenkernel/intern/blendfile_link_append.c b/source/blender/blenkernel/intern/blendfile_link_append.c index ebf48acde0f..4dd225c09ec 100644 --- a/source/blender/blenkernel/intern/blendfile_link_append.c +++ b/source/blender/blenkernel/intern/blendfile_link_append.c @@ -61,7 +61,7 @@ static CLG_LogRef LOG = {"bke.blendfile_link_append"}; typedef struct BlendfileLinkAppendContextItem { /** Name of the ID (without the heading two-chars IDcode). */ char *name; - /** All libs (from BlendfileLinkAppendContext.libraries) to try to load this ID from. */ + /** All libraries (from #BlendfileLinkAppendContext.libraries) to try to load this ID from. */ BLI_bitmap *libraries; /** ID type. */ short idcode; @@ -493,6 +493,7 @@ static void loose_data_instantiate_ensure_active_collection( static void loose_data_instantiate_object_base_instance_init(Main *bmain, Collection *collection, Object *ob, + const Scene *scene, ViewLayer *view_layer, const View3D *v3d, const int flag, @@ -506,7 +507,7 @@ static void loose_data_instantiate_object_base_instance_init(Main *bmain, } BKE_collection_object_add(bmain, collection, ob); - + BKE_view_layer_synced_ensure(scene, view_layer); Base *base = BKE_view_layer_base_find(view_layer, ob); if (v3d != NULL) { @@ -686,8 +687,14 @@ static void loose_data_instantiate_collection_process( /* TODO: why is it OK to make this active here but not in other situations? * See other callers of #object_base_instance_init */ const bool set_active = set_selected; - loose_data_instantiate_object_base_instance_init( - bmain, active_collection, ob, view_layer, v3d, lapp_context->params->flag, set_active); + loose_data_instantiate_object_base_instance_init(bmain, + active_collection, + ob, + scene, + view_layer, + v3d, + lapp_context->params->flag, + set_active); /* Assign the collection. */ ob->instance_collection = collection; @@ -698,6 +705,7 @@ static void loose_data_instantiate_collection_process( else { /* Add collection as child of active collection. */ BKE_collection_child_add(bmain, active_collection, collection); + BKE_view_layer_synced_ensure(scene, view_layer); if ((lapp_context->params->flag & FILE_AUTOSELECT) != 0) { LISTBASE_FOREACH (CollectionObject *, coll_ob, &collection->gobject) { @@ -717,6 +725,7 @@ static void loose_data_instantiate_object_process(LooseDataInstantiateContext *i { BlendfileLinkAppendContext *lapp_context = instantiate_context->lapp_context; Main *bmain = lapp_context->params->bmain; + const Scene *scene = lapp_context->params->context.scene; ViewLayer *view_layer = lapp_context->params->context.view_layer; const View3D *v3d = lapp_context->params->context.v3d; @@ -762,6 +771,7 @@ static void loose_data_instantiate_object_process(LooseDataInstantiateContext *i loose_data_instantiate_object_base_instance_init(bmain, active_collection, ob, + scene, view_layer, v3d, lapp_context->params->flag, @@ -809,6 +819,7 @@ static void loose_data_instantiate_obdata_process(LooseDataInstantiateContext *i loose_data_instantiate_object_base_instance_init(bmain, active_collection, ob, + scene, view_layer, v3d, lapp_context->params->flag, @@ -1232,8 +1243,9 @@ void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *re mainl = BLO_library_link_begin(&blo_handle, libname, lapp_context->params); lib = mainl->curlib; - BLI_assert(lib); - UNUSED_VARS_NDEBUG(lib); + BLI_assert(lib != NULL); + /* In case lib was already existing but not found originally, see T99820. */ + lib->id.tag &= ~LIB_TAG_MISSING; if (mainl->versionfile < 250) { BKE_reportf(reports, @@ -1246,7 +1258,7 @@ void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *re } /* For each lib file, we try to link all items belonging to that lib, - * and tag those successful to not try to load them again with the other libs. */ + * and tag those successful to not try to load them again with the other libraries. */ for (item_idx = 0, itemlink = lapp_context->items.list; itemlink; item_idx++, itemlink = itemlink->next) { BlendfileLinkAppendContextItem *item = itemlink->link; @@ -1260,7 +1272,7 @@ void BKE_blendfile_link(BlendfileLinkAppendContext *lapp_context, ReportList *re mainl, &blo_handle, item->idcode, item->name, lapp_context->params); if (new_id) { - /* If the link is successful, clear item's libs 'todo' flags. + /* If the link is successful, clear item's libraries 'todo' flags. * This avoids trying to link same item with other libraries to come. */ BLI_bitmap_set_all(item->libraries, false, lapp_context->num_libraries); item->new_id = new_id; @@ -1482,6 +1494,7 @@ void BKE_blendfile_library_relocate(BlendfileLinkAppendContext *lapp_context, * code is wrong, we need to redo it here after adding them back to main. */ BKE_main_id_refcount_recompute(bmain, false); + BKE_layer_collection_resync_forbid(); /* Note that in reload case, we also want to replace indirect usages. */ const short remap_flags = ID_REMAP_SKIP_NEVER_NULL_USAGE | (do_reload ? 0 : ID_REMAP_SKIP_INDIRECT_USAGE); @@ -1511,6 +1524,8 @@ void BKE_blendfile_library_relocate(BlendfileLinkAppendContext *lapp_context, id_us_plus_no_lib(&old_key->id); } } + BKE_layer_collection_resync_allow(); + BKE_main_collection_sync_remap(bmain); BKE_main_unlock(bmain); @@ -1602,6 +1617,9 @@ void BKE_blendfile_library_relocate(BlendfileLinkAppendContext *lapp_context, (id->tag & LIB_TAG_PRE_EXISTING) == 0) { continue; } + if ((id->override_library->reference->tag & LIB_TAG_MISSING) == 0) { + id->tag &= ~LIB_TAG_MISSING; + } if ((id->override_library->reference->tag & LIB_TAG_PRE_EXISTING) == 0) { BKE_lib_override_library_update(bmain, id); } |