Anim: Fix issue where F-Curves were half-initialized when importing USD

Fix an issue where imported F-Curves were allocated but not zeroed out,
when importing skeletal animation from USD.

When growing the F-Curve array, `BKE_fcurve_bezt_resize()` will now zero
out new array elements, instead of leaving the initialisation to the
caller. There are many fields in `BezTriple`, and the caller is likely
to only set those that can be imported (like the keyframe coordinates &
handles).

This fixes an issue introduced in 857743db9d.

Pull Request: https://projects.blender.org/blender/blender/pulls/135448
This commit is contained in:
Sybren A. Stüvel
2025-03-05 12:20:40 +01:00
parent a03077c22d
commit aada31c041
2 changed files with 10 additions and 2 deletions
+2 -2
View File
@@ -482,8 +482,8 @@ bool BKE_fcurve_bezt_subdivide_handles(BezTriple *bezt,
*
* \param new_totvert: new number of elements in the FCurve's `bezt` array.
*
* \note When increasing the size of the array, newly added elements are not initialized. That is
* left to the caller.
* \note When increasing the size of the array, newly added elements (that is, in the
* [old_totvert..new_totvert) interval) are zero-initialized.
*/
void BKE_fcurve_bezt_resize(FCurve *fcu, int new_totvert);
@@ -1622,6 +1622,14 @@ void BKE_fcurve_bezt_resize(FCurve *fcu, const int new_totvert)
fcu->bezt = static_cast<BezTriple *>(
MEM_reallocN(fcu->bezt, new_totvert * sizeof(*(fcu->bezt))));
/* Zero out all the newly-allocated beztriples. This is necessary, as it is likely that only some
* of the fields will actually be updated by the caller. */
const int old_totvert = fcu->totvert;
if (new_totvert > old_totvert) {
memset(&fcu->bezt[old_totvert], 0, sizeof(fcu->bezt[0]) * (new_totvert - old_totvert));
}
fcu->totvert = new_totvert;
}