From 540fd10b4fda80eb9c806aae29363daefd2f990e Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Mon, 28 Feb 2022 09:03:47 +0100 Subject: Fix T95992: Crash Ancored strokes 2d texture painting. When using ancored stroked the diameter of the stroke can be 0 what leads to a division by zero that on certain platforms wrap to a large negative number that cannot be looked up. This fix will clamp the size of the brush to 1. --- source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source') diff --git a/source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc b/source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc index 8d57a3d9152..5133b5fc982 100644 --- a/source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc +++ b/source/blender/editors/sculpt_paint/paint_image_2d_curve_mask.cc @@ -69,6 +69,7 @@ static void update_curve_mask(CurveMaskCache *curve_mask_cache, { BLI_assert(curve_mask_cache->curve_mask != nullptr); int offset = (int)floorf(diameter / 2.0f); + int clamped_radius = max_ff(radius, 1.0); unsigned short *m = curve_mask_cache->curve_mask; @@ -92,7 +93,7 @@ static void update_curve_mask(CurveMaskCache *curve_mask_cache, pixel_xy[1] = static_cast(y) + aa_offset; for (int j = 0; j < aa_samples; j++) { const float len = len_v2v2(pixel_xy, bpos); - const int sample_index = min_ii((len / radius) * CurveSamplesBaseLen, + const int sample_index = min_ii((len / clamped_radius) * CurveSamplesBaseLen, CurveSamplesLen - 1); const float sample_weight = curve_mask_cache->sampled_curve[sample_index]; -- cgit v1.2.3