[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [36863] branches/soc-2011-pepper/source/ blender/blenkernel/intern/constraint.c: Bugfix: Limit Distance constraint could be doing divide-by-zero in a

Joshua Leung aligorith at gmail.com
Tue May 24 14:20:02 CEST 2011


Revision: 36863
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=36863
Author:   aligorith
Date:     2011-05-24 12:20:02 +0000 (Tue, 24 May 2011)
Log Message:
-----------
Bugfix: Limit Distance constraint could be doing divide-by-zero in a
few cases, especially if the object and target are at the same
location when the constraint is created.

This manisfested as the constrained object disappearing when the
constraint was added, only reappearing after transforming it a bit.

Modified Paths:
--------------
    branches/soc-2011-pepper/source/blender/blenkernel/intern/constraint.c

Modified: branches/soc-2011-pepper/source/blender/blenkernel/intern/constraint.c
===================================================================
--- branches/soc-2011-pepper/source/blender/blenkernel/intern/constraint.c	2011-05-24 12:12:12 UTC (rev 36862)
+++ branches/soc-2011-pepper/source/blender/blenkernel/intern/constraint.c	2011-05-24 12:20:02 UTC (rev 36863)
@@ -2642,15 +2642,13 @@
 		/* set distance (flag is only set when user demands it) */
 		if (data->dist == 0)
 			data->dist= dist;
-			
-		// FIXME: dist may be 0!
 		
 		/* check if we're which way to clamp from, and calculate interpolation factor (if needed) */
 		if (data->mode == LIMITDIST_OUTSIDE) {
 			/* if inside, then move to surface */
 			if (dist <= data->dist) {
 				clamp_surf= 1;
-				sfac= data->dist / dist;
+				if (dist != 0.0f) sfac= data->dist / dist;
 			}
 			/* if soft-distance is enabled, start fading once owner is dist+softdist from the target */
 			else if (data->flag & LIMITDIST_USESOFT) {
@@ -2663,14 +2661,14 @@
 			/* if outside, then move to surface */
 			if (dist >= data->dist) {
 				clamp_surf= 1;
-				sfac= data->dist / dist;
+				if (dist != 0.0f) sfac= data->dist / dist;
 			}
 			/* if soft-distance is enabled, start fading once owner is dist-soft from the target */
 			else if (data->flag & LIMITDIST_USESOFT) {
 				// FIXME: there's a problem with "jumping" when this kicks in
 				if (dist >= (data->dist - data->soft)) {
 					sfac = (float)( data->soft*(1.0f - expf(-(dist - data->dist)/data->soft)) + data->dist );
-					sfac /= dist;
+					if (dist != 0.0f) sfac /= dist;
 					
 					clamp_surf= 1;
 				}
@@ -2679,7 +2677,7 @@
 		else {
 			if (IS_EQF(dist, data->dist)==0) {
 				clamp_surf= 1;
-				sfac= data->dist / dist;
+				if (dist != 0.0f) sfac= data->dist / dist;
 			}
 		}
 		




More information about the Bf-blender-cvs mailing list