Render: frame_position no longer panics on a zero or negative frame rate

A project file can carry footage with a frame rate of den 0; frame_position
divided by zero while rendering it. Treat non-positive rates as having no
frame to land between.
This commit is contained in:
jayzed80
2026-10-30 15:53:49 +00:00
parent ec7ced1f05
commit 588560c368
2 changed files with 11 additions and 0 deletions
+4
View File
@@ -80,6 +80,10 @@ pub(crate) fn frame_blend_mode(ctx: &EvalCtx, layer: &Layer) -> FrameBlend {
/// fraction (0..1) of the way to the next frame. Exact (integer tick arithmetic), so frames that
/// line up exactly report a fraction of 0.
pub fn frame_position(t: Tick, rate: FrameRate) -> (i64, f64) {
// A project file can carry a zero or negative rate; there are no frames to land between.
if rate.num <= 0 || rate.den <= 0 {
return (0, 0.0);
}
let num = t.0 as i128 * rate.num as i128;
let den = TICKS_PER_SECOND as i128 * rate.den as i128;
(num.div_euclid(den) as i64, num.rem_euclid(den) as f64 / den as f64)
+7
View File
@@ -167,3 +167,10 @@ fn time_stretched_precomp_frame_mixes() {
let img = crate::render_frame(&p, cid, FrameRate::FPS_30.tick_of(1), 1.0);
assert!(img.get(12, 10)[3] < 1e-3 && (img.get(17, 10)[3] - 1.0).abs() < 1e-3 && (img.get(22, 10)[3] - 1.0).abs() < 1e-3 && img.get(27, 10)[3] < 1e-3);
}
#[test]
fn frame_position_survives_degenerate_rates() {
for rate in [FrameRate { num: 24, den: 0 }, FrameRate { num: 0, den: 1 }, FrameRate { num: -24, den: 1 }] {
assert_eq!(frame_position(Tick(1_000_000), rate), (0, 0.0));
}
}