diff options
author | Sybren A. Stüvel <sybren@blender.org> | 2020-10-12 17:55:46 +0300 |
---|---|---|
committer | Sybren A. Stüvel <sybren@blender.org> | 2020-10-12 18:00:11 +0300 |
commit | 5e6c7de3e918f7ecbf4ea898f6e5b8a2373ad17e (patch) | |
tree | 0011f9a4c38186e1fea9b325e843a9b23d8645e6 /source/blender/blenkernel/intern | |
parent | 0d3e192660bfa231aacf80d3e5a3d750155798ea (diff) |
Animation: enforce that the active keyframe is always selected
Check selection state in `BKE_fcurve_active_keyframe_index()`, and only
return the active keyframe index when that keyframe is actually selected.
This is now also asserted in the `BKE_fcurve_active_keyframe_set()` function,
which is now also used when inserting a keyframe.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/fcurve.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/source/blender/blenkernel/intern/fcurve.c b/source/blender/blenkernel/intern/fcurve.c index d2a9064a373..d57ef45107c 100644 --- a/source/blender/blenkernel/intern/fcurve.c +++ b/source/blender/blenkernel/intern/fcurve.c @@ -839,6 +839,8 @@ bool BKE_fcurve_calc_range( */ void BKE_fcurve_active_keyframe_set(FCurve *fcu, const BezTriple *active_bezt) { + /* The active keyframe should always be selected. */ + BLI_assert(active_bezt->f2 & SELECT); fcu->active_keyframe_index = (active_bezt == NULL) ? FCURVE_ACTIVE_KEYFRAME_NONE : active_bezt - fcu->bezt; } @@ -850,12 +852,18 @@ int BKE_fcurve_active_keyframe_index(const FCurve *fcu) { const int active_keyframe_index = fcu->active_keyframe_index; - /* Sanity checks. */ + /* Array access boundary checks. */ if ((fcu->bezt == NULL) || (active_keyframe_index >= fcu->totvert) || (active_keyframe_index < 0)) { return FCURVE_ACTIVE_KEYFRAME_NONE; } + const BezTriple *active_bezt = &fcu->bezt[active_keyframe_index]; + if ((active_bezt->f2 & SELECT) == 0) { + /* The active keyframe should always be selected. If it's not selected, it can't be active. */ + return FCURVE_ACTIVE_KEYFRAME_NONE; + } + return active_keyframe_index; } |