diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-07-26 16:49:20 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-07-26 16:49:20 +0300 |
commit | 3ed5c9a610b348841f1e48736f02d73976f034d4 (patch) | |
tree | 55bb80e49d06a872e273461be50c132cec2ca43a /source/blender/makesrna/intern/rna_ID.c | |
parent | 40a45e393e7651604f97202d21b6bfd5079253b8 (diff) |
PyAPI: Store PyInstances for ID's
This means once an ID is created,
it will keep using the same PyObject instance.
This has some advantages:
- Avoids unnecessary re-creation of instances on UI poll / redraw.
- Accessing free'd ID's gives an exception instead of crashing.
(long standing annoyance!, though this only applies to ID's
and not yet other data that uses the ID's - vertices for eg).
- Allows using instance comparison (a little faster).
Note that the instances won't be kept between undo.
Diffstat (limited to 'source/blender/makesrna/intern/rna_ID.c')
-rw-r--r-- | source/blender/makesrna/intern/rna_ID.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c index 3d162137bd1..1c6172ef667 100644 --- a/source/blender/makesrna/intern/rna_ID.c +++ b/source/blender/makesrna/intern/rna_ID.c @@ -394,6 +394,14 @@ static void rna_ID_animation_data_free(ID *id, Main *bmain) DEG_relations_tag_update(bmain); } +#ifdef WITH_PYTHON +void **rna_ID_instance(PointerRNA *ptr) +{ + ID *id = (ID *)ptr->data; + return &id->py_instance; +} +#endif + static void rna_IDPArray_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) { IDProperty *prop = (IDProperty *)ptr->data; @@ -1071,6 +1079,10 @@ static void rna_def_ID(BlenderRNA *brna) "Tag the ID to update its display data, " "e.g. when calling :class:`bpy.types.Scene.update`"); RNA_def_enum_flag(func, "refresh", update_flag_items, 0, "", "Type of updates to perform"); + +#ifdef WITH_PYTHON + RNA_def_struct_register_funcs(srna, NULL, NULL, "rna_ID_instance"); +#endif } static void rna_def_library(BlenderRNA *brna) |