Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDalai Felinto <dfelinto@gmail.com>2017-05-03 12:38:17 +0300
committerDalai Felinto <dfelinto@gmail.com>2017-05-03 12:51:49 +0300
commit2a8608294597f82add9c69b64bc11b9c492d46ac (patch)
treea5c67c6f822981daf48daa4228587706b9830328 /source/blender/blenkernel/intern/layer.c
parent66c74242bba3c2962ff5c3ddc02409171ec86dc3 (diff)
Validate collection properties at readile
The alternative would be to do version bump + doversioning every time a new property is added.
Diffstat (limited to 'source/blender/blenkernel/intern/layer.c')
-rw-r--r--source/blender/blenkernel/intern/layer.c57
1 files changed, 57 insertions, 0 deletions
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();
+}