Revision: 17902
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17902
Author:   aligorith
Date:     2008-12-17 07:00:17 +0100 (Wed, 17 Dec 2008)

Log Message:
-----------
AnimSys2: Bugfix #18086 - Hang on changing the main axis of a clamp-to 
constraint

Fixed the code to be able to handle cases where the size of the chosen axis was 
so small (i.e. close to zero) that it is likely to cause division-by-zero 
errors and also result in infinite loops in places... Fix will be ported to 
trunk at some point. 

Modified Paths:
--------------
    branches/animsys2/source/blender/blenkernel/intern/constraint.c

Modified: branches/animsys2/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/animsys2/source/blender/blenkernel/intern/constraint.c     
2008-12-17 05:40:40 UTC (rev 17901)
+++ branches/animsys2/source/blender/blenkernel/intern/constraint.c     
2008-12-17 06:00:17 UTC (rev 17902)
@@ -3022,44 +3022,53 @@
                                float len= (curveMax[clamp_axis] - 
curveMin[clamp_axis]);
                                float offset;
                                
-                               /* find bounding-box range where target is 
located */
-                               if (ownLoc[clamp_axis] < curveMin[clamp_axis]) {
-                                       /* bounding-box range is before */
-                                       offset= curveMin[clamp_axis];
-                                       
-                                       while (ownLoc[clamp_axis] < offset)
-                                               offset -= len;
-                                       
-                                       /* now, we calculate as per normal, 
except using offset instead of curveMin[clamp_axis] */
-                                       curvetime = (ownLoc[clamp_axis] - 
offset) / (len);
-                               }
-                               else if (ownLoc[clamp_axis] > 
curveMax[clamp_axis]) {
-                                       /* bounding-box range is after */
-                                       offset= curveMax[clamp_axis];
-                                       
-                                       while (ownLoc[clamp_axis] > offset) {
-                                               if ((offset + len) > 
ownLoc[clamp_axis])
-                                                       break;
-                                               else
-                                                       offset += len;
+                               /* check to make sure len is not so close to 
zero that it'll cause errors */
+                               if (IS_EQ(len, 0) == 0) {
+                                       /* find bounding-box range where target 
is located */
+                                       if (ownLoc[clamp_axis] < 
curveMin[clamp_axis]) {
+                                               /* bounding-box range is before 
*/
+                                               offset= curveMin[clamp_axis];
+                                               
+                                               while (ownLoc[clamp_axis] < 
offset)
+                                                       offset -= len;
+                                               
+                                               /* now, we calculate as per 
normal, except using offset instead of curveMin[clamp_axis] */
+                                               curvetime = (ownLoc[clamp_axis] 
- offset) / (len);
                                        }
-                                       
-                                       /* now, we calculate as per normal, 
except using offset instead of curveMax[clamp_axis] */
-                                       curvetime = (ownLoc[clamp_axis] - 
offset) / (len);
+                                       else if (ownLoc[clamp_axis] > 
curveMax[clamp_axis]) {
+                                               /* bounding-box range is after 
*/
+                                               offset= curveMax[clamp_axis];
+                                               
+                                               while (ownLoc[clamp_axis] > 
offset) {
+                                                       if ((offset + len) > 
ownLoc[clamp_axis])
+                                                               break;
+                                                       else
+                                                               offset += len;
+                                               }
+                                               
+                                               /* now, we calculate as per 
normal, except using offset instead of curveMax[clamp_axis] */
+                                               curvetime = (ownLoc[clamp_axis] 
- offset) / (len);
+                                       }
+                                       else {
+                                               /* as the location falls within 
bounds, just calculate */
+                                               curvetime = (ownLoc[clamp_axis] 
- curveMin[clamp_axis]) / (len);
+                                       }
                                }
                                else {
-                                       /* as the location falls within bounds, 
just calculate */
-                                       curvetime = (ownLoc[clamp_axis] - 
curveMin[clamp_axis]) / (len);
+                                       /* as length is close to zero, 
curvetime by default should be 0 (i.e. the start) */
+                                       curvetime= 0.0f;
                                }
                        }
                        else {
                                /* no cyclic, so position is clamped to within 
the bounding box */
                                if (ownLoc[clamp_axis] <= curveMin[clamp_axis])
-                                       curvetime = 0.0;
+                                       curvetime = 0.0f;
                                else if (ownLoc[clamp_axis] >= 
curveMax[clamp_axis])
-                                       curvetime = 1.0;
-                               else
+                                       curvetime = 1.0f;
+                               else if ( IS_EQ((curveMax[clamp_axis] - 
curveMin[clamp_axis]), 0) == 0 )
                                        curvetime = (ownLoc[clamp_axis] - 
curveMin[clamp_axis]) / (curveMax[clamp_axis] - curveMin[clamp_axis]);
+                               else 
+                                       curvetime = 0.0f;
                        }
                        
                        /* 3. position on curve */


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

Reply via email to