diff options
author | Campbell Barton <ideasman42@gmail.com> | 2012-07-16 16:49:01 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2012-07-16 16:49:01 +0400 |
commit | f6b3a6e6f380df6ebcf405eb53f6c22dbd51f8f6 (patch) | |
tree | c08b6f85b32df7933acd3bc682386ecaf92fa3e6 /source/blender/blenkernel/intern/mask_rasterize.c | |
parent | e32d963478b2589e2f48bf86eb3894fcac58efe5 (diff) |
fix for occasional crash with splines a lot larger then the view
Diffstat (limited to 'source/blender/blenkernel/intern/mask_rasterize.c')
-rw-r--r-- | source/blender/blenkernel/intern/mask_rasterize.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/source/blender/blenkernel/intern/mask_rasterize.c b/source/blender/blenkernel/intern/mask_rasterize.c index ef87f47993c..29e7c94f431 100644 --- a/source/blender/blenkernel/intern/mask_rasterize.c +++ b/source/blender/blenkernel/intern/mask_rasterize.c @@ -383,14 +383,21 @@ static void layer_bucket_init(MaskRasterLayer *layer, const float pixel_size) 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 @@ static float maskrasterize_layer_z_depth_quad(const float pt[2], 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 |