[Bf-blender-cvs] [03d482d2129] master: Fix T63896: Removing Drivers in Python Leads to Crash

Sergey Sharybin noreply at git.blender.org
Fri Apr 26 15:31:32 CEST 2019


Commit: 03d482d212945eb46144524ccb8824d6889e8039
Author: Sergey Sharybin
Date:   Fri Apr 26 15:25:41 2019 +0200
Branches: master
https://developer.blender.org/rB03d482d212945eb46144524ccb8824d6889e8039

Fix T63896: Removing Drivers in Python Leads to Crash

Adding and removing drivers must always tag relations for update.

===================================================================

M	source/blender/makesrna/intern/rna_animation.c
M	source/blender/python/intern/CMakeLists.txt
M	source/blender/python/intern/bpy_rna_anim.c

===================================================================

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);
   }



More information about the Bf-blender-cvs mailing list