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:
authorSergey Sharybin <sergey.vfx@gmail.com>2016-02-10 17:09:45 +0300
committerSergey Sharybin <sergey.vfx@gmail.com>2016-02-12 17:27:33 +0300
commit28604c46a137c1288cc7a494b36ed72e44a0ab8b (patch)
tree3ce7de49d1604cdec2ce420a117ae1ab59df2404 /intern/cycles/blender/blender_util.h
parentec9977855f9264ecf6af5b4c8e6d10324a02028e (diff)
Cycles: Make Blender importer more forward compatible
Basically the idea is to make code robust against extending enum options in the future by falling back to a known safe default setting when RNA is set to something unknown. While this approach solves the issues similar to T47377, but it wouldn't really help when/if any of the RNA values gets ever deprecated and removed. There'll be no simple solution to that apart from defining explicit mapping from RNA value to Cycles one. Another part which isn't so great actually is that we now have to have some enum guards and give some explicit values to the enum items, but we can live with that perhaps. Reviewers: dingto, juicyfruit, lukasstockner97, brecht Reviewed By: brecht Differential Revision: https://developer.blender.org/D1785
Diffstat (limited to 'intern/cycles/blender/blender_util.h')
-rw-r--r--intern/cycles/blender/blender_util.h21
1 files changed, 18 insertions, 3 deletions
diff --git a/intern/cycles/blender/blender_util.h b/intern/cycles/blender/blender_util.h
index 06176b2d289..cefc01bfa91 100644
--- a/intern/cycles/blender/blender_util.h
+++ b/intern/cycles/blender/blender_util.h
@@ -357,9 +357,24 @@ static inline void set_int(PointerRNA& ptr, const char *name, int value)
RNA_int_set(&ptr, name, value);
}
-static inline int get_enum(PointerRNA& ptr, const char *name)
-{
- return RNA_enum_get(&ptr, name);
+/* Get a RNA enum value with sanity check: if the RNA value is above num_values
+ * the function will return a fallback default value.
+ *
+ * NOTE: This function assumes that RNA enum values are a continuous sequence
+ * from 0 to num_values-1. Be careful to use it with enums where some values are
+ * deprecated!
+ */
+static inline int get_enum(PointerRNA& ptr,
+ const char *name,
+ int num_values = -1,
+ int default_value = -1)
+{
+ int value = RNA_enum_get(&ptr, name);
+ if(num_values != -1 && value >= num_values) {
+ assert(default_value != -1);
+ value = default_value;
+ }
+ return value;
}
static inline string get_enum_identifier(PointerRNA& ptr, const char *name)