Fix #131681: Grease Pencil: Build modifier concurrent mode div by zero

There could be strokes that have zero lengths (a dot), in this case a
NaN factor was given to the final build function, leading to invalid
index when accessing arrays. Now `get_stroke_factor` will return either
0.0f or 1.0f (depending on input factor) when stroke has zero total
length.

Pull Request: https://projects.blender.org/blender/blender/pulls/131683
This commit is contained in:
YimingWu
2024-12-10 17:19:10 +01:00
committed by Falk David
parent e24eadbb42
commit 7f8b811a42

View File

@@ -131,8 +131,11 @@ static Array<int> point_counts_to_keep_concurrent(const bke::CurvesGeometry &cur
auto get_stroke_factor = [&](const float factor, const int index) {
const bool stroke_cyclic = cyclic[index];
const float max_factor = max_length /
curves.evaluated_length_total_for_curve(index, stroke_cyclic);
const float total_length = curves.evaluated_length_total_for_curve(index, stroke_cyclic);
if (total_length == 0) {
return factor > 0.5f ? 1.0f : 0.0f;
}
const float max_factor = max_length / total_length;
if (time_alignment == MOD_GREASE_PENCIL_BUILD_TIMEALIGN_START) {
if (clamp_points) {
return std::clamp(factor * max_factor, 0.0f, 1.0f);