Files
test2/source/blender/geometry/GEO_interpolate_curves.hh
Lukas Tönne 63c460d93d Fix #134482: Grease Pencil: Interpolation creates uninitialized values
This was partially fixed in ef844bad but left some unhandled corner cases with
uninitialized memory.

The core problem is that the `dst_curve_mask` used by the interpolation
functions can contain indices that don't actually exist in either the "from" or
"to" source drawings. Specifically when the "from" drawing has more curves, the
indices are still used but the supplemental `to_curve_indices` array contains
`-1` entries, indicating that only the "from" curve should be used.

The main copy code for positions takes this into account, but the generic copy
of attributes below that does not! It passes the `dst_curve_mask` straight into
the `array_utils` functions and that causes crashes. The original fix in
ef844bad was to clamp the size of the index mask, but the way this was done
could lead to empty index masks, leaving attribute values uninitialized.

The correct solution is to use index masks that exclude invalid entries for the
respective source curves. The new masks are non-overlapping, so the full set of
destination curves can be filled by combining these masks.

Pull Request: https://projects.blender.org/blender/blender/pulls/134865
2025-02-24 10:26:53 +01:00

39 lines
1.6 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "BKE_curves.hh"
namespace blender::geometry {
/**
* Create new curves that are interpolated between "from" and "to" curves.
* \param dst_curve_mask: Set of curves in \a dst_curves that are being filled.
*/
void interpolate_curves(const bke::CurvesGeometry &from_curves,
const bke::CurvesGeometry &to_curves,
Span<int> from_curve_indices,
Span<int> to_curve_indices,
const IndexMask &dst_curve_mask,
Span<bool> dst_curve_flip_direction,
float mix_factor,
bke::CurvesGeometry &dst_curves,
IndexMaskMemory &memory);
void interpolate_curves_with_samples(const bke::CurvesGeometry &from_curves,
const bke::CurvesGeometry &to_curves,
Span<int> from_curve_indices,
Span<int> to_curve_indices,
Span<int> from_sample_indices,
Span<int> to_sample_indices,
Span<float> from_sample_factors,
Span<float> to_sample_factors,
const IndexMask &dst_curve_mask,
float mix_factor,
bke::CurvesGeometry &dst_curves,
IndexMaskMemory &memory);
} // namespace blender::geometry