Fix #128935: Preview range to selected keyframes wrong

Depending on from where this functionality was called, it behaved
differently (there are three operators for this).

- from the GE, it uses `get_graph_keyframe_extents` [which falls back to
existing scene (preview) start/end frames if no real extends are found]
- from the NLA, it uses `get_nlastrip_extents`[which falls back to
existing scene start/end frames if no real extends are found]
- elsewhere (and this was reported in #128935) it uses
`get_keyframe_extents` but did not consider if extends were really
found.

The last case lead to startframe being set higher than endframe causing
a crash on playback.

This PR checks the return value of `get_keyframe_extents` [which tells
us if extends were found] and cancels out early.

NOTE: it would probably be nice if the behavior was consistent across
all editors, but since I think the right behavior is to not do anything
if nothing is selected (after all the description is "based on range of
selected keyframes"), I am going for correct behavior of
`ACTION_OT_previewrange_set` but leave the Graph Editor and NLA editor
operators untouched for the time being.

Pull Request: https://projects.blender.org/blender/blender/pulls/128981
This commit is contained in:
Philipp Oeser
2024-10-14 11:51:24 +02:00
committed by Philipp Oeser
parent 99b876e2bc
commit 1246baa81b

View File

@@ -274,10 +274,11 @@ static int actkeys_previewrange_exec(bContext *C, wmOperator * /*op*/)
return OPERATOR_CANCELLED;
}
scene = ac.scene;
/* set the range directly */
get_keyframe_extents(&ac, &min, &max, true);
if (!get_keyframe_extents(&ac, &min, &max, true)) {
return OPERATOR_CANCELLED;
}
scene = ac.scene;
scene->r.flag |= SCER_PRV_RANGE;
scene->r.psfra = floorf(min);
scene->r.pefra = ceilf(max);