From aada31c0411fe13db637578504cd35d71eb29556 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 5 Mar 2025 12:20:40 +0100 Subject: [PATCH] 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 --- source/blender/blenkernel/BKE_fcurve.hh | 4 ++-- source/blender/blenkernel/intern/fcurve.cc | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/BKE_fcurve.hh b/source/blender/blenkernel/BKE_fcurve.hh index 43e2f5245eb..99f529880ab 100644 --- a/source/blender/blenkernel/BKE_fcurve.hh +++ b/source/blender/blenkernel/BKE_fcurve.hh @@ -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); diff --git a/source/blender/blenkernel/intern/fcurve.cc b/source/blender/blenkernel/intern/fcurve.cc index 0d9ee282c0c..454b2b8497f 100644 --- a/source/blender/blenkernel/intern/fcurve.cc +++ b/source/blender/blenkernel/intern/fcurve.cc @@ -1622,6 +1622,14 @@ void BKE_fcurve_bezt_resize(FCurve *fcu, const int new_totvert) fcu->bezt = static_cast( 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; }