Revision: 23879
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=23879
Author:   aligorith
Date:     2009-10-16 08:24:39 +0200 (Fri, 16 Oct 2009)

Log Message:
-----------
Graph Editor - Transform Crash Fix

The code for transforming a mixture of keyframes with bezier and non-bezier 
interpolation was crashing. 

The old code only took all the handles when a keyframe was bezier, and one when 
it was not; but sometimes this underestimated the situation (the first handle 
is only really used if the previous keyframe was bezier, as per the standard 
evaluation rules for these, but it didn't really check for this). Now, it just 
adds them whenever, since there is the possibility that keyframes may be moved 
before other unselected ones, in which case the handles may become invalid.

Thanks to Lee (from Durian, who found the crash), and Jess Balint (who had 
submitted a patch with some steps towards fixing this)

Modified Paths:
--------------
    trunk/blender/source/blender/editors/transform/transform_conversions.c

Modified: trunk/blender/source/blender/editors/transform/transform_conversions.c
===================================================================
--- trunk/blender/source/blender/editors/transform/transform_conversions.c      
2009-10-16 00:23:40 UTC (rev 23878)
+++ trunk/blender/source/blender/editors/transform/transform_conversions.c      
2009-10-16 06:24:39 UTC (rev 23879)
@@ -3342,7 +3342,7 @@
        bAnimListElem *ale;
        int filter;
        
-       BezTriple *bezt, *prevbezt;
+       BezTriple *bezt;
        int count=0, i;
        float cfra;
        char side;
@@ -3382,30 +3382,29 @@
                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++;
+               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 {
-                                               /* 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++;
-                                       }
+                                       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 @@
                        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) {
+                               /* 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);
+                               }
+                               else
+                                       h1= 0;
+                               if (bezt->f3 & SELECT) {
+                                       if (hdata==NULL)
                                                hdata = 
initTransDataCurveHandes(td, bezt);
-                                               bezt_to_transdata(td++, td2d++, 
adt, bezt->vec[0], bezt->vec[1], 1, 1, intvals);
-                                       }
-                                       else
-                                               h1= 0;
+                                       bezt_to_transdata(td++, td2d++, adt, 
bezt->vec[2], 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
+                                       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)) {


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to