From 2a8608294597f82add9c69b64bc11b9c492d46ac Mon Sep 17 00:00:00 2001 From: Dalai Felinto Date: Wed, 3 May 2017 11:38:17 +0200 Subject: Validate collection properties at readile The alternative would be to do version bump + doversioning every time a new property is added. --- source/blender/blenkernel/intern/layer.c | 57 ++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'source/blender/blenkernel/intern/layer.c') diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c index b74b6ac7e6b..d9398ae83c7 100644 --- a/source/blender/blenkernel/intern/layer.c +++ b/source/blender/blenkernel/intern/layer.c @@ -1253,6 +1253,55 @@ void BKE_layer_collection_engine_settings_create(IDProperty *root) collection_engine_settings_init(root, true); } +/** + * Reference of IDProperty group scene collection settings + * Used when reading blendfiles, to see if there is any missing settings. + */ +static IDProperty *root_reference = NULL; + +/** + * Free the reference scene collection settings IDProperty group. + */ +static void layer_collection_engine_settings_validate_init(void) +{ + if (root_reference == NULL) { + IDPropertyTemplate val = {0}; + root_reference = IDP_New(IDP_GROUP, &val, ROOT_PROP); + BKE_layer_collection_engine_settings_create(root_reference); + } +} + +/** + * Free the reference scene collection settings IDProperty group. + */ +static void layer_collection_engine_settings_validate_free(void) +{ + if (root_reference != NULL) { + IDP_FreeProperty(root_reference); + MEM_freeN(root_reference); + root_reference = NULL; + } +} + +/** + * Make sure Scene has all required collection settings. + */ +void BKE_layer_collection_engine_settings_validate(Scene *scene) +{ + if (root_reference == NULL) { + layer_collection_engine_settings_validate_init(); + } + + if (scene->collection_properties == NULL) { + IDPropertyTemplate val = {0}; + scene->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP); + BKE_layer_collection_engine_settings_create(scene->collection_properties); + } + else { + IDP_MergeGroup(scene->collection_properties, root_reference, false); + } +} + /* ---------------------------------------------------------------------- */ /* Iterators */ @@ -1464,3 +1513,11 @@ void BKE_layer_eval_layer_collection_post(struct EvaluationContext *UNUSED(eval_ } } } + +/** + * Free any static allocated memory. + */ +void BKE_layer_exit() +{ + layer_collection_engine_settings_validate_free(); +} -- cgit v1.2.3