[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48965] trunk/blender/source/blender/ blenkernel/intern/mask_rasterize.c: fix for occasional crash with splines a lot larger then the view

Campbell Barton ideasman42 at gmail.com
Mon Jul 16 14:49:01 CEST 2012


Revision: 48965
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48965
Author:   campbellbarton
Date:     2012-07-16 12:49:01 +0000 (Mon, 16 Jul 2012)
Log Message:
-----------
fix for occasional crash with splines a lot larger then the view

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c

Modified: trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c	2012-07-16 12:08:28 UTC (rev 48964)
+++ trunk/blender/source/blender/blenkernel/intern/mask_rasterize.c	2012-07-16 12:49:01 UTC (rev 48965)
@@ -383,14 +383,21 @@
 				CLAMP(ymax, 0.0f,  1.0f);
 
 				{
-					const unsigned int xi_min = (unsigned int) ((xmin - layer->bounds.xmin) * layer->buckets_xy_scalar[0]);
-					const unsigned int xi_max = (unsigned int) ((xmax - layer->bounds.xmin) * layer->buckets_xy_scalar[0]);
-					const unsigned int yi_min = (unsigned int) ((ymin - layer->bounds.ymin) * layer->buckets_xy_scalar[1]);
-					const unsigned int yi_max = (unsigned int) ((ymax - layer->bounds.ymin) * layer->buckets_xy_scalar[1]);
+					unsigned int xi_min = (unsigned int) ((xmin - layer->bounds.xmin) * layer->buckets_xy_scalar[0]);
+					unsigned int xi_max = (unsigned int) ((xmax - layer->bounds.xmin) * layer->buckets_xy_scalar[0]);
+					unsigned int yi_min = (unsigned int) ((ymin - layer->bounds.ymin) * layer->buckets_xy_scalar[1]);
+					unsigned int yi_max = (unsigned int) ((ymax - layer->bounds.ymin) * layer->buckets_xy_scalar[1]);
 					void *face_index_void = SET_UINT_IN_POINTER(face_index);
 
 					unsigned int xi, yi;
 
+					/* this should _almost_ never happen but since it can in extreme cases,
+					 * we have to clamp the values or we overrun the buffer and crash */
+					CLAMP(xi_min, 0, layer->buckets_x - 1);
+					CLAMP(xi_max, 0, layer->buckets_x - 1);
+					CLAMP(yi_min, 0, layer->buckets_y - 1);
+					CLAMP(yi_max, 0, layer->buckets_y - 1);
+
 					for (yi = yi_min; yi <= yi_max; yi++) {
 						unsigned int bucket_index = (layer->buckets_x * yi) + xi_min;
 						for (xi = xi_min; xi <= xi_max; xi++, bucket_index++) {
@@ -866,7 +873,7 @@
 	float w[4];
 	barycentric_weights_v2_quad(v1, v2, v3, v4, pt, w);
 	//return (v1[2] * w[0]) + (v2[2] * w[1]) + (v3[2] * w[2]) + (v4[2] * w[3]);
-	return (1.0f * w[2]) + (1.0f * w[3]);  /* we can make this assumption for small speedup */
+	return w[2] + w[3];  /* we can make this assumption for small speedup */
 }
 #endif
 




More information about the Bf-blender-cvs mailing list