Collection: Revert moving owner_id to runtime data.

While it may have been working from a practical PoV (not certain though,
since some bug would prevent clearing runtime data when writing embedded
Scene collection in current code), this is semantically wrong.

The owner of an embedded ID is a critical piece of information in
Blender data structure and ID management code. Having it written in
.blend files is also a potential good source of data for investigating
issues.

Further more, this handling of `owner` ID data is somewhat generic now
in ID management, so if this data should be considered runtime, then the
change should also be made in NodeTree and Key IDs.

This commit partially reverts 44dd3308a5, in the future I'd like to
be involved in the review of changes affecting ID management.

NOTE: fix for embedded collection runtime data not being cleared on
write will be committed separately.
This commit is contained in:
Bastien Montagne
2023-11-23 14:11:14 +01:00
parent 3dc119a440
commit a1507baead
4 changed files with 15 additions and 17 deletions

View File

@@ -179,7 +179,7 @@ static void collection_foreach_id(ID *id, LibraryForeachIDData *data)
BKE_LIB_FOREACHID_PROCESS_ID(
data,
collection->runtime.owner_id,
collection->owner_id,
(IDWALK_CB_LOOPBACK | IDWALK_CB_NEVER_SELF | IDWALK_CB_READFILE_IGNORE));
LISTBASE_FOREACH (CollectionObject *, cob, &collection->gobject) {
@@ -225,12 +225,11 @@ static ID **collection_owner_pointer_get(ID *id)
Collection *master_collection = (Collection *)id;
BLI_assert((master_collection->flag & COLLECTION_IS_MASTER) != 0);
BLI_assert(master_collection->runtime.owner_id != nullptr);
BLI_assert(GS(master_collection->runtime.owner_id->name) == ID_SCE);
BLI_assert(((Scene *)master_collection->runtime.owner_id)->master_collection ==
master_collection);
BLI_assert(master_collection->owner_id != nullptr);
BLI_assert(GS(master_collection->owner_id->name) == ID_SCE);
BLI_assert(((Scene *)master_collection->owner_id)->master_collection == master_collection);
return &master_collection->runtime.owner_id;
return &master_collection->owner_id;
}
void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection)
@@ -294,7 +293,7 @@ void BKE_collection_blend_read_data(BlendDataReader *reader, Collection *collect
memset(&collection->runtime, 0, sizeof(collection->runtime));
collection->flag &= ~COLLECTION_FLAG_ALL_RUNTIME;
collection->runtime.owner_id = owner_id;
collection->owner_id = owner_id;
BLO_read_list(reader, &collection->gobject);
BLO_read_list(reader, &collection->children);
@@ -872,7 +871,7 @@ Collection *BKE_collection_master_add(Scene *scene)
Collection *master_collection = static_cast<Collection *>(
BKE_libblock_alloc(nullptr, ID_GR, BKE_SCENE_COLLECTION_NAME, LIB_ID_CREATE_NO_MAIN));
master_collection->id.flag |= LIB_EMBEDDED_DATA;
master_collection->runtime.owner_id = &scene->id;
master_collection->owner_id = &scene->id;
master_collection->flag |= COLLECTION_IS_MASTER;
master_collection->color_tag = COLLECTION_COLOR_NONE;

View File

@@ -278,7 +278,7 @@ static void scene_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int
(ID *)scene_src->master_collection,
(ID **)&scene_dst->master_collection,
flag_private_id_data);
scene_dst->master_collection->runtime.owner_id = &scene_dst->id;
scene_dst->master_collection->owner_id = &scene_dst->id;
}
/* View Layers */

View File

@@ -1912,18 +1912,18 @@ static void after_liblink_id_embedded_id_process(BlendLibReader *reader, ID *id)
if (scene->master_collection != nullptr) {
after_liblink_id_process(reader, &scene->master_collection->id);
if (scene->master_collection->runtime.owner_id == nullptr) {
if (scene->master_collection->owner_id == nullptr) {
CLOG_WARN(&LOG,
"NULL owner_id pointer for embedded Scene Collection of %s, should never happen",
id->name);
scene->master_collection->runtime.owner_id = id;
scene->master_collection->owner_id = id;
}
else if (scene->master_collection->runtime.owner_id != id) {
else if (scene->master_collection->owner_id != id) {
CLOG_WARN(&LOG,
"Inconsistent owner_id pointer for embedded Scene Collection of %s, should "
"never happen",
id->name);
scene->master_collection->runtime.owner_id = id;
scene->master_collection->owner_id = id;
}
}
}

View File

@@ -84,9 +84,6 @@ enum eCollectionLineArt_Flags {
};
typedef struct Collection_Runtime {
/** The ID owning this collection, in case it is an embedded one. */
ID *owner_id;
/**
* Cache of objects in this collection and all its children.
* This is created on demand when e.g. some physics simulation needs it,
@@ -111,6 +108,9 @@ typedef struct Collection_Runtime {
typedef struct Collection {
ID id;
/** The ID owning this collection, in case it is an embedded one. */
ID *owner_id;
/** CollectionObject. */
ListBase gobject;
/** CollectionChild. */
@@ -131,7 +131,6 @@ typedef struct Collection {
uint8_t lineart_intersection_mask;
uint8_t lineart_intersection_priority;
void *_pad1;
struct ViewLayer *view_layer DNA_DEPRECATED;
/* Keep last. */