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.
This commit is contained in:
Jeroen Bakker 2022-02-28 09:03:47 +01:00
parent 2a644deaa7
commit 540fd10b4f
Notes: blender-bot 2023-02-13 22:20:49 +01:00
Referenced by issue #95992, Crash: painting 2D textures with anchored strokes in 3.1 Beta
1 changed files with 2 additions and 1 deletions

View File

@ -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<float>(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];