[Bf-blender-cvs] [19a89797c3a] master: Fix crash when trying to decimate baked fcurve channels

Sebastian Parborg noreply at git.blender.org
Fri Dec 6 16:58:55 CET 2019


Commit: 19a89797c3a37f0e5b8957857536b539e2ea938a
Author: Sebastian Parborg
Date:   Fri Dec 6 16:58:14 2019 +0100
Branches: master
https://developer.blender.org/rB19a89797c3a37f0e5b8957857536b539e2ea938a

Fix crash when trying to decimate baked fcurve channels

No curve data was available for the modal decimate operator.
Added a check for when the curve has baked data.

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

M	source/blender/editors/space_graph/graph_edit.c

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

diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index 2948566ff0e..4d2772aabee 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -1375,9 +1375,14 @@ static void decimate_reset_bezts(tDecimateGraphOp *dgo)
   ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
 
   /* Loop through filtered data and reset bezts. */
-  for (ale = anim_data.first, link_bezt = dgo->bezt_arr_list.first; ale;
-       ale = ale->next, link_bezt = link_bezt->next) {
+  for (ale = anim_data.first, link_bezt = dgo->bezt_arr_list.first; ale; ale = ale->next) {
     FCurve *fcu = (FCurve *)ale->key_data;
+
+    if (fcu->bezt == NULL) {
+      /* This curve is baked, skip it */
+      continue;
+    }
+
     tBeztCopyData *data = link_bezt->data;
 
     const int arr_size = sizeof(BezTriple) * data->tot_vert;
@@ -1388,6 +1393,8 @@ static void decimate_reset_bezts(tDecimateGraphOp *dgo)
     fcu->totvert = data->tot_vert;
 
     memcpy(fcu->bezt, data->bezt, arr_size);
+
+    link_bezt = link_bezt->next;
   }
 
   ANIM_animdata_freelist(&anim_data);
@@ -1413,7 +1420,9 @@ static void decimate_exit(bContext *C, wmOperator *op)
   BLI_freelistN(&dgo->bezt_arr_list);
   MEM_freeN(dgo);
 
+  /* Return to normal cursor and header status. */
   WM_cursor_modal_restore(win);
+  ED_area_status_text(dgo->sa, NULL);
 
   /* cleanup */
   op->customdata = NULL;
@@ -1497,6 +1506,12 @@ static int graphkeys_decimate_invoke(bContext *C, wmOperator *op, const wmEvent
     /* Loop through filtered data and copy the curves. */
     for (ale = anim_data.first; ale; ale = ale->next) {
       FCurve *fcu = (FCurve *)ale->key_data;
+
+      if (fcu->bezt == NULL) {
+        /* This curve is baked, skip it */
+        continue;
+      }
+
       const int arr_size = sizeof(BezTriple) * fcu->totvert;
 
       tBeztCopyData *copy = MEM_mallocN(sizeof(tBeztCopyData), "bezts_copy");
@@ -1518,6 +1533,13 @@ static int graphkeys_decimate_invoke(bContext *C, wmOperator *op, const wmEvent
     ANIM_animdata_freelist(&anim_data);
   }
 
+  if (dgo->bezt_arr_list.first == NULL) {
+    WM_report(RPT_WARNING,
+              "Fcurve Decimate: Can't decimate baked channels. Unbake them and try again.");
+    decimate_exit(C, op);
+    return OPERATOR_CANCELLED;
+  }
+
   WM_event_add_modal_handler(C, op);
   return OPERATOR_RUNNING_MODAL;
 }
@@ -1556,8 +1578,6 @@ static int graphkeys_decimate_modal(bContext *C, wmOperator *op, const wmEvent *
     case RETKEY:
     case PADENTER: {
       if (event->val == KM_PRESS) {
-        ED_area_status_text(dgo->sa, NULL);
-
         decimate_exit(C, op);
 
         return OPERATOR_FINISHED;
@@ -1568,9 +1588,6 @@ static int graphkeys_decimate_modal(bContext *C, wmOperator *op, const wmEvent *
     case ESCKEY: /* cancel */
     case RIGHTMOUSE: {
       if (event->val == KM_PRESS) {
-        /* Return to normal cursor and header status. */
-        ED_area_status_text(dgo->sa, NULL);
-
         decimate_reset_bezts(dgo);
 
         WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);



More information about the Bf-blender-cvs mailing list