Graph Editor - Transform Crash Fix
[blender.git] / source / blender / editors / transform / transform_conversions.c
index 496a96653719f6dae1e2104d2359a97519fecac4..abcf1748149b77f0eab57aaee028fbbef8bc0e66 100644 (file)
@@ -3342,7 +3342,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
        bAnimListElem *ale;
        int filter;
        
-       BezTriple *bezt, *prevbezt;
+       BezTriple *bezt;
        int count=0, i;
        float cfra;
        char side;
@@ -3382,29 +3382,28 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                else
                        cfra = (float)CFRA;
                
+               /* F-Curve may not have any keyframes */
+               if (fcu->bezt == NULL)
+                       continue;
+               
                /* only include BezTriples whose 'keyframe' occurs on the same side of the current frame as mouse */
-               if (fcu->bezt) {
-                       for (i=0, bezt=fcu->bezt; i < fcu->totvert; i++, bezt++) {
-                               if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) {
-                                       if (v2d->around == V3D_LOCAL) {
-                                               /* for local-pivot we only need to count the number of selected handles only, so that centerpoitns don't
-                                                * don't get moved wrong
-                                                */
-                                               if (bezt->ipo == BEZT_IPO_BEZ) {
-                                                       if (bezt->f1 & SELECT) count++;
-                                                       if (bezt->f3 & SELECT) count++;
-                                               }
-                                               else if (bezt->f2 & SELECT) count++;
-                                       }
-                                       else {
-                                               /* for 'normal' pivots */
-                                               if (bezt->ipo == BEZT_IPO_BEZ) {
-                                                       if (bezt->f1 & SELECT) count++;
-                                                       if (bezt->f2 & SELECT) count++;
-                                                       if (bezt->f3 & SELECT) count++;
-                                               }
-                                               else if (bezt->f2 & SELECT) count++;
+               for (i=0, bezt=fcu->bezt; i < fcu->totvert; i++, bezt++) {
+                       if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) {
+                               if (v2d->around == V3D_LOCAL) {
+                                       /* for local-pivot we only need to count the number of selected handles only, so that centerpoints don't
+                                        * don't get moved wrong
+                                        */
+                                       if (bezt->ipo == BEZT_IPO_BEZ) {
+                                               if (bezt->f1 & SELECT) count++;
+                                               if (bezt->f3 & SELECT) count++;
                                        }
+                                       else if (bezt->f2 & SELECT) count++; // TODO: could this cause problems?
+                               }
+                               else {
+                                       /* for 'normal' pivots - just include anything that is selected */
+                                       if (bezt->f1 & SELECT) count++;
+                                       if (bezt->f2 & SELECT) count++;
+                                       if (bezt->f3 & SELECT) count++;
                                }
                        }
                }
@@ -3440,38 +3439,35 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
                        cfra = BKE_nla_tweakedit_remap(adt, (float)CFRA, NLATIME_CONVERT_UNMAP);
                else
                        cfra = (float)CFRA;
+                       
+               /* F-Curve may not have any keyframes */
+               if (fcu->bezt == NULL)
+                       continue;
                
                /* only include BezTriples whose 'keyframe' occurs on the same side of the current frame as mouse (if applicable) */
-               bezt= fcu->bezt;
-               prevbezt= NULL;
-               
-               for (i=0; i < fcu->totvert; i++, prevbezt=bezt, bezt++) {
+               for (i=0, bezt= fcu->bezt; i < fcu->totvert; i++, bezt++) {
                        if (FrameOnMouseSide(side, bezt->vec[1][0], cfra)) {
                                TransDataCurveHandleFlags *hdata = NULL;
                                short h1=1, h2=1;
                                
-                               /* only include handles if selected, and interpolaton mode uses beztriples */
-                               if ( (!prevbezt && (bezt->ipo==BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo==BEZT_IPO_BEZ)) ) {
-                                       if (bezt->f1 & SELECT) {
-                                               hdata = initTransDataCurveHandes(td, bezt);
-                                               bezt_to_transdata(td++, td2d++, adt, bezt->vec[0], bezt->vec[1], 1, 1, intvals);
-                                       }
-                                       else
-                                               h1= 0;
+                               /* only include handles if selected, irrespective of the interpolation modes */
+                               if (bezt->f1 & SELECT) {
+                                       hdata = initTransDataCurveHandes(td, bezt);
+                                       bezt_to_transdata(td++, td2d++, adt, bezt->vec[0], bezt->vec[1], 1, 1, intvals);
                                }
-                               if (bezt->ipo == BEZT_IPO_BEZ) {
-                                       if (bezt->f3 & SELECT) {
-                                               if (hdata==NULL)
-                                                       hdata = initTransDataCurveHandes(td, bezt);
-                                               bezt_to_transdata(td++, td2d++, adt, bezt->vec[2], bezt->vec[1], 1, 1, intvals);
-                                       }
-                                       else
-                                               h2= 0;
+                               else
+                                       h1= 0;
+                               if (bezt->f3 & SELECT) {
+                                       if (hdata==NULL)
+                                               hdata = initTransDataCurveHandes(td, bezt);
+                                       bezt_to_transdata(td++, td2d++, adt, bezt->vec[2], bezt->vec[1], 1, 1, intvals);
                                }
+                               else
+                                       h2= 0;
                                
                                /* only include main vert if selected */
                                if (bezt->f2 & SELECT) {
-                                       /* if scaling around individuals centers, do no include keyframes */
+                                       /* if scaling around individuals centers, do not include keyframes */
                                        if (v2d->around != V3D_LOCAL) {
                                                /* if handles were not selected, store their selection status */
                                                if (!(bezt->f1 & SELECT) && !(bezt->f3 & SELECT)) {