From 8fc2b634684dca6348c91becbae8ccb95a2fe701 Mon Sep 17 00:00:00 2001 From: Bastien Montagne Date: Thu, 23 Nov 2023 15:06:21 +0100 Subject: [PATCH] Fix (unreported) Scene Collection runtime data not cleared on write. --- source/blender/blenkernel/BKE_collection.h | 4 ++++ source/blender/blenkernel/intern/collection.cc | 11 ++++++++--- source/blender/blenkernel/intern/scene.cc | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h index 3f3e5296550..a79b57caa71 100644 --- a/source/blender/blenkernel/BKE_collection.h +++ b/source/blender/blenkernel/BKE_collection.h @@ -312,6 +312,10 @@ bool BKE_collection_validate(struct Collection *collection); /* .blend file I/O */ +/** Perform some pre-writing cleanup on the COllection data itself (_not_ in any sub-data + * referenced by pointers). To be called before writing the Collection struct itself. */ +void BKE_collection_blend_write_prepare_nolib(struct BlendWriter *writer, + struct Collection *collection); void BKE_collection_blend_write_nolib(struct BlendWriter *writer, struct Collection *collection); void BKE_collection_blend_read_data(struct BlendDataReader *reader, struct Collection *collection, diff --git a/source/blender/blenkernel/intern/collection.cc b/source/blender/blenkernel/intern/collection.cc index cd3b6144b7a..07e79e2e456 100644 --- a/source/blender/blenkernel/intern/collection.cc +++ b/source/blender/blenkernel/intern/collection.cc @@ -232,6 +232,13 @@ static ID **collection_owner_pointer_get(ID *id) return &master_collection->owner_id; } +void BKE_collection_blend_write_prepare_nolib(BlendWriter * /*writer*/, Collection *collection) +{ + memset(&collection->runtime, 0, sizeof(collection->runtime)); + /* Clean up, important in undo case to reduce false detection of changed data-blocks. */ + collection->flag &= ~COLLECTION_FLAG_ALL_RUNTIME; +} + void BKE_collection_blend_write_nolib(BlendWriter *writer, Collection *collection) { BKE_id_blend_write(writer, &collection->id); @@ -252,9 +259,7 @@ static void collection_blend_write(BlendWriter *writer, ID *id, const void *id_a { Collection *collection = (Collection *)id; - memset(&collection->runtime, 0, sizeof(collection->runtime)); - /* Clean up, important in undo case to reduce false detection of changed data-blocks. */ - collection->flag &= ~COLLECTION_FLAG_ALL_RUNTIME; + BKE_collection_blend_write_prepare_nolib(writer, collection); /* write LibData */ BLO_write_id_struct(writer, Collection, id_address, &collection->id); diff --git a/source/blender/blenkernel/intern/scene.cc b/source/blender/blenkernel/intern/scene.cc index fa06ff28e16..20aacd42a52 100644 --- a/source/blender/blenkernel/intern/scene.cc +++ b/source/blender/blenkernel/intern/scene.cc @@ -1186,6 +1186,9 @@ static void scene_blend_write(BlendWriter *writer, ID *id, const void *id_addres if (sce->master_collection) { BLO_write_init_id_buffer_from_id( temp_embedded_id_buffer, &sce->master_collection->id, BLO_write_is_undo(writer)); + BKE_collection_blend_write_prepare_nolib( + writer, + reinterpret_cast(BLO_write_get_id_buffer_temp_id(temp_embedded_id_buffer))); BLO_write_struct_at_address(writer, Collection, sce->master_collection,