diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-04-26 16:25:41 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2019-04-26 16:31:13 +0300 |
commit | 03d482d212945eb46144524ccb8824d6889e8039 (patch) | |
tree | 66e11c55d5382bbcb1681f8c918b21f7fb620443 /source | |
parent | 7440f98f980b203d73c047e6aefc144495b4c3c6 (diff) |
Fix T63896: Removing Drivers in Python Leads to Crash
Adding and removing drivers must always tag relations for update.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/makesrna/intern/rna_animation.c | 12 | ||||
-rw-r--r-- | source/blender/python/intern/CMakeLists.txt | 1 | ||||
-rw-r--r-- | source/blender/python/intern/bpy_rna_anim.c | 8 |
3 files changed, 16 insertions, 5 deletions
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c index 27a9333cd9e..15429ec6b5e 100644 --- a/source/blender/makesrna/intern/rna_animation.c +++ b/source/blender/makesrna/intern/rna_animation.c @@ -600,7 +600,7 @@ static FCurve *rna_Driver_from_existing(AnimData *adt, bContext *C, FCurve *src_ } static FCurve *rna_Driver_new( - ID *id, AnimData *adt, ReportList *reports, const char *rna_path, int array_index) + ID *id, AnimData *adt, Main *bmain, ReportList *reports, const char *rna_path, int array_index) { if (rna_path[0] == '\0') { BKE_report(reports, RPT_ERROR, "F-Curve data path empty, invalid argument"); @@ -615,16 +615,20 @@ static FCurve *rna_Driver_new( short add_mode = 1; FCurve *fcu = verify_driver_fcurve(id, rna_path, array_index, add_mode); BLI_assert(fcu != NULL); + + DEG_relations_tag_update(bmain); + return fcu; } -static void rna_Driver_remove(AnimData *adt, ReportList *reports, FCurve *fcu) +static void rna_Driver_remove(AnimData *adt, Main *bmain, ReportList *reports, FCurve *fcu) { if (!BLI_remlink_safe(&adt->drivers, fcu)) { BKE_report(reports, RPT_ERROR, "Driver not found in this animation data"); return; } free_fcurve(fcu); + DEG_relations_tag_update(bmain); } static FCurve *rna_Driver_find(AnimData *adt, @@ -1129,7 +1133,7 @@ static void rna_api_animdata_drivers(BlenderRNA *brna, PropertyRNA *cprop) /* AnimData.drivers.new(...) */ func = RNA_def_function(srna, "new", "rna_Driver_new"); - RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS); + RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_REPORTS | FUNC_USE_MAIN); parm = RNA_def_string(func, "data_path", NULL, 0, "Data Path", "F-Curve data path to use"); RNA_def_parameter_flags(parm, 0, PARM_REQUIRED); RNA_def_int(func, "index", 0, 0, INT_MAX, "Index", "Array index", 0, INT_MAX); @@ -1139,7 +1143,7 @@ static void rna_api_animdata_drivers(BlenderRNA *brna, PropertyRNA *cprop) /* AnimData.drivers.remove(...) */ func = RNA_def_function(srna, "remove", "rna_Driver_remove"); - RNA_def_function_flag(func, FUNC_USE_REPORTS); + RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_MAIN); parm = RNA_def_pointer(func, "driver", "FCurve", "", ""); RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED); diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt index 7eb008efeef..fc945562c98 100644 --- a/source/blender/python/intern/CMakeLists.txt +++ b/source/blender/python/intern/CMakeLists.txt @@ -24,6 +24,7 @@ set(INC ../../blenlib ../../blenloader ../../blentranslation + ../../depsgraph ../../editors/include ../../gpu ../../imbuf diff --git a/source/blender/python/intern/bpy_rna_anim.c b/source/blender/python/intern/bpy_rna_anim.c index 2cd8c8641bb..79c31c8caad 100644 --- a/source/blender/python/intern/bpy_rna_anim.c +++ b/source/blender/python/intern/bpy_rna_anim.c @@ -55,6 +55,8 @@ #include "../generic/python_utildefines.h" +#include "DEG_depsgraph_build.h" + /* for keyframes and drivers */ static int pyrna_struct_anim_args_parse_ex(PointerRNA *ptr, const char *error_prefix, @@ -586,7 +588,9 @@ PyObject *pyrna_struct_driver_add(BPy_StructRNA *self, PyObject *args) ret = pyrna_struct_CreatePyObject(&tptr); } + bContext *context = BPy_GetContext(); WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL); + DEG_relations_tag_update(CTX_data_main(context)); } else { /* XXX, should be handled by reports, */ @@ -644,7 +648,9 @@ PyObject *pyrna_struct_driver_remove(BPy_StructRNA *self, PyObject *args) return NULL; } - WM_event_add_notifier(BPy_GetContext(), NC_ANIMATION | ND_FCURVES_ORDER, NULL); + bContext *context = BPy_GetContext(); + WM_event_add_notifier(context, NC_ANIMATION | ND_FCURVES_ORDER, NULL); + DEG_relations_tag_update(CTX_data_main(context)); return PyBool_FromLong(result); } |