diff options
44 files changed, 132 insertions, 58 deletions
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h index f35dafa15a8..d15aebfe03d 100644 --- a/source/blender/blenkernel/BKE_collection.h +++ b/source/blender/blenkernel/BKE_collection.h @@ -77,8 +77,6 @@ struct Collection *BKE_collection_duplicate(struct Main *bmain, /* Master Collection for Scene */ struct Collection *BKE_collection_master_add(void); -struct Scene *BKE_collection_master_scene_search(const struct Main *bmain, - const struct Collection *master_collection); /* Collection Objects */ diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h index edfc96f3059..4578f1c3ca5 100644 --- a/source/blender/blenkernel/BKE_idtype.h +++ b/source/blender/blenkernel/BKE_idtype.h @@ -95,6 +95,8 @@ typedef void (*IDTypeForeachCacheFunction)(struct ID *id, IDTypeForeachCacheFunctionCallback function_callback, void *user_data); +typedef struct ID *(*IDTypeEmbeddedOwnerGetFunction)(struct Main *bmain, struct ID *id); + typedef void (*IDTypeBlendWriteFunction)(struct BlendWriter *writer, struct ID *id, const void *id_address); @@ -181,6 +183,11 @@ typedef struct IDTypeInfo { */ IDTypeForeachCacheFunction foreach_cache; + /** + * For embedded IDs, return their owner ID. + */ + IDTypeEmbeddedOwnerGetFunction owner_get; + /* ********** Callbacks for reading and writing .blend files. ********** */ /** diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 8652adecaf9..76d5eb945bb 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -442,7 +442,6 @@ struct bNodeTree *ntreeCopyTree(struct Main *bmain, const struct bNodeTree *ntre struct bNodeTree **BKE_ntree_ptr_from_id(struct ID *id); struct bNodeTree *ntreeFromID(struct ID *id); -struct ID *BKE_node_tree_find_owner_ID(struct Main *bmain, struct bNodeTree *ntree); void ntreeFreeLocalNode(struct bNodeTree *ntree, struct bNode *node); void ntreeFreeLocalTree(struct bNodeTree *ntree); diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c index 94680dc5c0c..06b8bd5f0f2 100644 --- a/source/blender/blenkernel/intern/action.c +++ b/source/blender/blenkernel/intern/action.c @@ -303,6 +303,7 @@ IDTypeInfo IDType_ID_AC = { .make_local = NULL, .foreach_id = action_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = action_blend_write, .blend_read_data = action_blend_read_data, diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c index a59ead84aca..83aab758f86 100644 --- a/source/blender/blenkernel/intern/armature.c +++ b/source/blender/blenkernel/intern/armature.c @@ -324,6 +324,7 @@ IDTypeInfo IDType_ID_AR = { .make_local = NULL, .foreach_id = armature_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = armature_blend_write, .blend_read_data = armature_blend_read_data, diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 59ff59b82e0..13ba1957a32 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -403,6 +403,7 @@ IDTypeInfo IDType_ID_BR = { .make_local = brush_make_local, .foreach_id = brush_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = brush_blend_write, .blend_read_data = brush_blend_read_data, diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c index 1e2139522f1..d233022fd3f 100644 --- a/source/blender/blenkernel/intern/cachefile.c +++ b/source/blender/blenkernel/intern/cachefile.c @@ -135,6 +135,7 @@ IDTypeInfo IDType_ID_CF = { .make_local = NULL, .foreach_id = NULL, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = cache_file_blend_write, .blend_read_data = cache_file_blend_read_data, diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index b0e3743add1..bab9e2a5592 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -196,6 +196,7 @@ IDTypeInfo IDType_ID_CA = { .make_local = camera_make_local, .foreach_id = camera_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = camera_blend_write, .blend_read_data = camera_blend_read_data, diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c index dd0572f9b12..28b91dcc8ce 100644 --- a/source/blender/blenkernel/intern/collection.c +++ b/source/blender/blenkernel/intern/collection.c @@ -172,6 +172,26 @@ static void collection_foreach_id(ID *id, LibraryForeachIDData *data) } } +static ID *collection_owner_get(Main *bmain, ID *id) +{ + if ((id->flag & LIB_EMBEDDED_DATA) == 0) { + return id; + } + BLI_assert((id->tag & LIB_TAG_NO_MAIN) == 0); + + Collection *master_collection = (Collection *)id; + BLI_assert((master_collection->flag & COLLECTION_IS_MASTER) != 0); + + for (Scene *scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) { + if (scene->master_collection == master_collection) { + return &scene->id; + } + } + + BLI_assert(!"Embedded collection with no owner. Critical Main inconsistency."); + return NULL; +} + void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection) { BKE_id_blend_write(writer, &collection->id); @@ -355,6 +375,7 @@ IDTypeInfo IDType_ID_GR = { .make_local = NULL, .foreach_id = collection_foreach_id, .foreach_cache = NULL, + .owner_get = collection_owner_get, .blend_write = collection_blend_write, .blend_read_data = collection_blend_read_data, @@ -839,19 +860,6 @@ Collection *BKE_collection_master_add() return master_collection; } -Scene *BKE_collection_master_scene_search(const Main *bmain, const Collection *master_collection) -{ - BLI_assert((master_collection->flag & COLLECTION_IS_MASTER) != 0); - - for (Scene *scene = bmain->scenes.first; scene != NULL; scene = scene->id.next) { - if (scene->master_collection == master_collection) { - return scene; - } - } - - return NULL; -} - /** \} */ /* -------------------------------------------------------------------- */ diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c index f4485b2565e..f3551c98f07 100644 --- a/source/blender/blenkernel/intern/curve.c +++ b/source/blender/blenkernel/intern/curve.c @@ -320,6 +320,7 @@ IDTypeInfo IDType_ID_CU = { .make_local = NULL, .foreach_id = curve_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = curve_blend_write, .blend_read_data = curve_blend_read_data, diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c index 25a0259abe3..febc9e24c9f 100644 --- a/source/blender/blenkernel/intern/font.c +++ b/source/blender/blenkernel/intern/font.c @@ -169,6 +169,7 @@ IDTypeInfo IDType_ID_VF = { .make_local = NULL, .foreach_id = NULL, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = vfont_blend_write, .blend_read_data = vfont_blend_read_data, diff --git a/source/blender/blenkernel/intern/gpencil.c b/source/blender/blenkernel/intern/gpencil.c index 28477e9dc30..00dcaad83db 100644 --- a/source/blender/blenkernel/intern/gpencil.c +++ b/source/blender/blenkernel/intern/gpencil.c @@ -322,6 +322,7 @@ IDTypeInfo IDType_ID_GD = { .make_local = NULL, .foreach_id = greasepencil_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = greasepencil_blend_write, .blend_read_data = greasepencil_blend_read_data, diff --git a/source/blender/blenkernel/intern/hair.c b/source/blender/blenkernel/intern/hair.c index f76e5a73478..2894d6daf23 100644 --- a/source/blender/blenkernel/intern/hair.c +++ b/source/blender/blenkernel/intern/hair.c @@ -190,6 +190,7 @@ IDTypeInfo IDType_ID_HA = { .make_local = NULL, .foreach_id = hair_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = hair_blend_write, .blend_read_data = hair_blend_read_data, diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 10f15519ea4..368b1c2e66b 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -331,6 +331,7 @@ IDTypeInfo IDType_ID_IM = { .make_local = NULL, .foreach_id = NULL, .foreach_cache = image_foreach_cache, + .owner_get = NULL, .blend_write = image_blend_write, .blend_read_data = image_blend_read_data, diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c index d43a0cb3813..bdc763cf4ca 100644 --- a/source/blender/blenkernel/intern/ipo.c +++ b/source/blender/blenkernel/intern/ipo.c @@ -193,6 +193,7 @@ IDTypeInfo IDType_ID_IP = { .make_local = NULL, .foreach_id = NULL, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = NULL, .blend_read_data = ipo_blend_read_data, diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index 540337b84b3..f2893e162cb 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -216,6 +216,7 @@ IDTypeInfo IDType_ID_KE = { .make_local = NULL, .foreach_id = shapekey_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, /* Could have one actually? */ .blend_write = shapekey_blend_write, .blend_read_data = shapekey_blend_read_data, diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index 625d2353e3e..678bd94b68b 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -198,6 +198,7 @@ IDTypeInfo IDType_ID_LT = { .make_local = NULL, .foreach_id = lattice_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = lattice_blend_write, .blend_read_data = lattice_blend_read_data, diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c index d2f1196d804..677b9497c98 100644 --- a/source/blender/blenkernel/intern/library.c +++ b/source/blender/blenkernel/intern/library.c @@ -77,6 +77,7 @@ IDTypeInfo IDType_ID_LI = { .make_local = NULL, .foreach_id = library_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = NULL, .blend_read_data = NULL, diff --git a/source/blender/blenkernel/intern/light.c b/source/blender/blenkernel/intern/light.c index 4a2afb7f5e6..d91d80ac683 100644 --- a/source/blender/blenkernel/intern/light.c +++ b/source/blender/blenkernel/intern/light.c @@ -202,6 +202,7 @@ IDTypeInfo IDType_ID_LA = { .make_local = NULL, .foreach_id = light_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = light_blend_write, .blend_read_data = light_blend_read_data, diff --git a/source/blender/blenkernel/intern/lightprobe.c b/source/blender/blenkernel/intern/lightprobe.c index 4ef3b8c3237..d872ecf7578 100644 --- a/source/blender/blenkernel/intern/lightprobe.c +++ b/source/blender/blenkernel/intern/lightprobe.c @@ -100,6 +100,7 @@ IDTypeInfo IDType_ID_LP = { .make_local = NULL, .foreach_id = lightprobe_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = lightprobe_blend_write, .blend_read_data = lightprobe_blend_read_data, diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c index 283e2a94732..26d9ab7a8c7 100644 --- a/source/blender/blenkernel/intern/linestyle.c +++ b/source/blender/blenkernel/intern/linestyle.c @@ -760,6 +760,7 @@ IDTypeInfo IDType_ID_LS = { .make_local = NULL, .foreach_id = linestyle_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = linestyle_blend_write, .blend_read_data = linestyle_blend_read_data, diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c index 83d9449934c..3a3ad9ef051 100644 --- a/source/blender/blenkernel/intern/mask.c +++ b/source/blender/blenkernel/intern/mask.c @@ -263,6 +263,7 @@ IDTypeInfo IDType_ID_MSK = { .make_local = NULL, .foreach_id = mask_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = mask_blend_write, .blend_read_data = mask_blend_read_data, diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c index 70906065347..37d47a984cc 100644 --- a/source/blender/blenkernel/intern/material.c +++ b/source/blender/blenkernel/intern/material.c @@ -267,6 +267,7 @@ IDTypeInfo IDType_ID_MA = { .make_local = NULL, .foreach_id = material_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = material_blend_write, .blend_read_data = material_blend_read_data, diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c index 849c7ef57fb..6bef11dea76 100644 --- a/source/blender/blenkernel/intern/mball.c +++ b/source/blender/blenkernel/intern/mball.c @@ -197,6 +197,7 @@ IDTypeInfo IDType_ID_MB = { .make_local = NULL, .foreach_id = metaball_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = metaball_blend_write, .blend_read_data = metaball_blend_read_data, diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c index c15484f8e72..e7a16463d87 100644 --- a/source/blender/blenkernel/intern/mesh.c +++ b/source/blender/blenkernel/intern/mesh.c @@ -357,6 +357,7 @@ IDTypeInfo IDType_ID_ME = { .make_local = NULL, .foreach_id = mesh_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = mesh_blend_write, .blend_read_data = mesh_blend_read_data, diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c index 0265e1c8b2c..017a73593ee 100644 --- a/source/blender/blenkernel/intern/movieclip.c +++ b/source/blender/blenkernel/intern/movieclip.c @@ -355,6 +355,7 @@ IDTypeInfo IDType_ID_MC = { .make_local = NULL, .foreach_id = movie_clip_foreach_id, .foreach_cache = movie_clip_foreach_cache, + .owner_get = NULL, .blend_write = movieclip_blend_write, .blend_read_data = movieclip_blend_read_data, diff --git a/source/blender/blenkernel/intern/node.cc b/source/blender/blenkernel/intern/node.cc index b96adce7cca..58003c03f8c 100644 --- a/source/blender/blenkernel/intern/node.cc +++ b/source/blender/blenkernel/intern/node.cc @@ -367,6 +367,35 @@ static void node_foreach_cache(ID *id, } } +static ID *node_owner_get(Main *bmain, ID *id) +{ + if ((id->flag & LIB_EMBEDDED_DATA) == 0) { + return id; + } + BLI_assert((id->tag & LIB_TAG_NO_MAIN) == 0); + + ListBase *lists[] = {&bmain->materials, + &bmain->lights, + &bmain->worlds, + &bmain->textures, + &bmain->scenes, + &bmain->linestyles, + &bmain->simulations, + nullptr}; + + bNodeTree *ntree = (bNodeTree *)id; + for (int i = 0; lists[i] != nullptr; i++) { + LISTBASE_FOREACH (ID *, id_iter, lists[i]) { + if (ntreeFromID(id_iter) == ntree) { + return id_iter; + } + } + } + + BLI_assert(!"Embedded node tree with no owner. Critical Main inconsistency."); + return nullptr; +} + static void write_node_socket_default_value(BlendWriter *writer, bNodeSocket *sock) { if (sock->default_value == nullptr) { @@ -916,6 +945,7 @@ IDTypeInfo IDType_ID_NT = { /* make_local */ nullptr, /* foreach_id */ node_foreach_id, /* foreach_cache */ node_foreach_cache, + /* owner_get */ node_owner_get, /* blend_write */ ntree_blend_write, /* blend_read_data */ ntree_blend_read_data, @@ -2980,29 +3010,6 @@ bNodeTree *ntreeFromID(ID *id) return (nodetree != nullptr) ? *nodetree : nullptr; } -/* Finds and returns the datablock that privately owns the given tree, or null. */ -ID *BKE_node_tree_find_owner_ID(Main *bmain, struct bNodeTree *ntree) -{ - ListBase *lists[] = {&bmain->materials, - &bmain->lights, - &bmain->worlds, - &bmain->textures, - &bmain->scenes, - &bmain->linestyles, - &bmain->simulations, - nullptr}; - - for (int i = 0; lists[i] != nullptr; i++) { - LISTBASE_FOREACH (ID *, id, lists[i]) { - if (ntreeFromID(id) == ntree) { - return id; - } - } - } - - return nullptr; -} - bool ntreeNodeExists(const bNodeTree *ntree, const bNode *testnode) { LISTBASE_FOREACH (const bNode *, node, &ntree->nodes) { diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c index 04071282a52..704d6d1cf4f 100644 --- a/source/blender/blenkernel/intern/object.c +++ b/source/blender/blenkernel/intern/object.c @@ -1148,6 +1148,7 @@ IDTypeInfo IDType_ID_OB = { .make_local = object_make_local, .foreach_id = object_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = object_blend_write, .blend_read_data = object_blend_read_data, diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 3c770a85b2a..d8fb2edb36d 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -151,6 +151,7 @@ IDTypeInfo IDType_ID_PAL = { .make_local = NULL, .foreach_id = NULL, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = palette_blend_write, .blend_read_data = palette_blend_read_data, @@ -216,6 +217,7 @@ IDTypeInfo IDType_ID_PC = { .make_local = NULL, .foreach_id = NULL, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = paint_curve_blend_write, .blend_read_data = paint_curve_blend_read_data, diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c index 21d1e070389..acda59ce96c 100644 --- a/source/blender/blenkernel/intern/particle.c +++ b/source/blender/blenkernel/intern/particle.c @@ -504,6 +504,7 @@ IDTypeInfo IDType_ID_PA = { .make_local = NULL, .foreach_id = particle_settings_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = particle_settings_blend_write, .blend_read_data = particle_settings_blend_read_data, diff --git a/source/blender/blenkernel/intern/pointcloud.cc b/source/blender/blenkernel/intern/pointcloud.cc index b9ff2a1179d..d9a7a376e2e 100644 --- a/source/blender/blenkernel/intern/pointcloud.cc +++ b/source/blender/blenkernel/intern/pointcloud.cc @@ -183,6 +183,7 @@ IDTypeInfo IDType_ID_PT = { /* make_local */ nullptr, /* foreach_id */ pointcloud_foreach_id, /* foreach_cache */ nullptr, + /* owner_get */ nullptr, /* blend_write */ pointcloud_blend_write, /* blend_read_data */ pointcloud_blend_read_data, diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c index c7279dbc815..3633dff8690 100644 --- a/source/blender/blenkernel/intern/scene.c +++ b/source/blender/blenkernel/intern/scene.c @@ -1718,6 +1718,7 @@ IDTypeInfo IDType_ID_SCE = { .make_local = NULL, .foreach_id = scene_foreach_id, .foreach_cache = scene_foreach_cache, + .owner_get = NULL, .blend_write = scene_blend_write, .blend_read_data = scene_blend_read_data, diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c index df239b0c4ee..07619466bc5 100644 --- a/source/blender/blenkernel/intern/screen.c +++ b/source/blender/blenkernel/intern/screen.c @@ -311,6 +311,7 @@ IDTypeInfo IDType_ID_SCR = { .make_local = NULL, .foreach_id = screen_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = screen_blend_write, /* Cannot be used yet, because #direct_link_screen has a return value. */ diff --git a/source/blender/blenkernel/intern/simulation.cc b/source/blender/blenkernel/intern/simulation.cc index 4e0a08455e6..6b46804c251 100644 --- a/source/blender/blenkernel/intern/simulation.cc +++ b/source/blender/blenkernel/intern/simulation.cc @@ -166,6 +166,7 @@ IDTypeInfo IDType_ID_SIM = { /* make_local */ nullptr, /* foreach_id */ simulation_foreach_id, /* foreach_cache */ nullptr, + /* owner_get */ nullptr, /* blend_write */ simulation_blend_write, /* blend_read_data */ simulation_blend_read_data, diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c index 0c917434bd1..a33fedb3ea6 100644 --- a/source/blender/blenkernel/intern/sound.c +++ b/source/blender/blenkernel/intern/sound.c @@ -214,6 +214,7 @@ IDTypeInfo IDType_ID_SO = { .make_local = NULL, .foreach_id = NULL, .foreach_cache = sound_foreach_cache, + .owner_get = NULL, .blend_write = sound_blend_write, .blend_read_data = sound_blend_read_data, diff --git a/source/blender/blenkernel/intern/speaker.c b/source/blender/blenkernel/intern/speaker.c index 9caeaf05e6a..af9b2268879 100644 --- a/source/blender/blenkernel/intern/speaker.c +++ b/source/blender/blenkernel/intern/speaker.c @@ -107,6 +107,7 @@ IDTypeInfo IDType_ID_SPK = { .make_local = NULL, .foreach_id = speaker_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = speaker_blend_write, .blend_read_data = speaker_blend_read_data, diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 9bf215515f7..43d587861a5 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -251,6 +251,7 @@ IDTypeInfo IDType_ID_TXT = { .make_local = NULL, .foreach_id = NULL, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = text_blend_write, .blend_read_data = text_blend_read_data, diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c index ce84bfcd95a..29c41b88135 100644 --- a/source/blender/blenkernel/intern/texture.c +++ b/source/blender/blenkernel/intern/texture.c @@ -219,6 +219,7 @@ IDTypeInfo IDType_ID_TE = { .make_local = NULL, .foreach_id = texture_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = texture_blend_write, .blend_read_data = texture_blend_read_data, diff --git a/source/blender/blenkernel/intern/volume.cc b/source/blender/blenkernel/intern/volume.cc index edf40ab3861..9b5231f7d6f 100644 --- a/source/blender/blenkernel/intern/volume.cc +++ b/source/blender/blenkernel/intern/volume.cc @@ -637,6 +637,7 @@ IDTypeInfo IDType_ID_VO = { /* make_local */ nullptr, /* foreach_id */ volume_foreach_id, /* foreach_cache */ volume_foreach_cache, + /* owner_get */ nullptr, /* blend_write */ volume_blend_write, /* blend_read_data */ volume_blend_read_data, diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c index 5a101cf009b..481d190952f 100644 --- a/source/blender/blenkernel/intern/workspace.c +++ b/source/blender/blenkernel/intern/workspace.c @@ -185,6 +185,7 @@ IDTypeInfo IDType_ID_WS = { .make_local = NULL, .foreach_id = workspace_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = workspace_blend_write, .blend_read_data = workspace_blend_read_data, diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c index a2ce37a5d90..e889d8af1d5 100644 --- a/source/blender/blenkernel/intern/world.c +++ b/source/blender/blenkernel/intern/world.c @@ -199,6 +199,7 @@ IDTypeInfo IDType_ID_WO = { .make_local = NULL, .foreach_id = world_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = world_blend_write, .blend_read_data = world_blend_read_data, diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c index e686648038d..0afc26e0d8a 100644 --- a/source/blender/editors/space_outliner/outliner_collections.c +++ b/source/blender/editors/space_outliner/outliner_collections.c @@ -28,6 +28,7 @@ #include "BKE_collection.h" #include "BKE_context.h" +#include "BKE_idtype.h" #include "BKE_layer.h" #include "BKE_lib_id.h" #include "BKE_main.h" @@ -361,8 +362,14 @@ void outliner_collection_delete( break; } if (parent->flag & COLLECTION_IS_MASTER) { - Scene *parent_scene = BKE_collection_master_scene_search(bmain, parent); - if (ID_IS_LINKED(parent_scene)) { + BLI_assert(parent->id.flag & LIB_EMBEDDED_DATA); + + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(&parent->id); + BLI_assert(id_type->owner_get != NULL); + + ID *scene_owner = id_type->owner_get(bmain, &parent->id); + BLI_assert(GS(scene_owner->name) == ID_SCE); + if (ID_IS_LINKED(scene_owner)) { skip = true; break; } @@ -592,11 +599,18 @@ static int collection_duplicate_exec(bContext *C, wmOperator *op) scene->master_collection; } else if (parent != NULL && (parent->flag & COLLECTION_IS_MASTER) != 0) { - Scene *scene = BKE_collection_master_scene_search(bmain, parent); - BLI_assert(scene != NULL); - if (ID_IS_LINKED(scene) || ID_IS_OVERRIDE_LIBRARY(scene)) { - scene = CTX_data_scene(C); - parent = ID_IS_LINKED(scene) ? NULL : scene->master_collection; + BLI_assert(parent->id.flag & LIB_EMBEDDED_DATA); + + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(&parent->id); + BLI_assert(id_type->owner_get != NULL); + + Scene *scene_owner = (Scene *)id_type->owner_get(bmain, &parent->id); + BLI_assert(scene_owner != NULL); + BLI_assert(GS(scene_owner->id.name) == ID_SCE); + + if (ID_IS_LINKED(scene_owner) || ID_IS_OVERRIDE_LIBRARY(scene_owner)) { + scene_owner = CTX_data_scene(C); + parent = ID_IS_LINKED(scene_owner) ? NULL : scene_owner->master_collection; } } diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c index d8c91cb2923..c5dd516d16e 100644 --- a/source/blender/makesrna/intern/rna_access.c +++ b/source/blender/makesrna/intern/rna_access.c @@ -5826,26 +5826,29 @@ ID *RNA_find_real_ID_and_path(Main *bmain, ID *id, const char **r_path) *r_path = ""; } - if ((id != NULL) && (id->flag & LIB_EMBEDDED_DATA)) { + if ((id == NULL) || (id->flag & LIB_EMBEDDED_DATA) == 0) { + return id; + } + + const IDTypeInfo *id_type = BKE_idtype_get_info_from_id(id); + if (r_path) { switch (GS(id->name)) { case ID_NT: - if (r_path) { - *r_path = "node_tree"; - } - return BKE_node_tree_find_owner_ID(bmain, (bNodeTree *)id); + *r_path = "node_tree"; + break; case ID_GR: - if (r_path) { - *r_path = "collection"; - } - return (ID *)BKE_collection_master_scene_search(bmain, (struct Collection *)id); - + *r_path = "collection"; + break; default: - return NULL; + BLI_assert(!"Missing handling of embedded id type."); } } - else { + + if (id_type->owner_get == NULL) { + BLI_assert(!"Missing handling of embedded id type."); return id; } + return id_type->owner_get(bmain, id); } static char *rna_prepend_real_ID_path(Main *bmain, ID *id, char *path, ID **r_real_id) diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index b43357b1462..a9c0d1dd8fe 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -272,6 +272,7 @@ IDTypeInfo IDType_ID_WM = { .make_local = NULL, .foreach_id = window_manager_foreach_id, .foreach_cache = NULL, + .owner_get = NULL, .blend_write = window_manager_blend_write, .blend_read_data = window_manager_blend_read_data, |