From a62564b567befbf3d0f9410cfb553454d5d610b0 Mon Sep 17 00:00:00 2001 From: arnav-hiwarkar Date: Tue, 17 Nov 2026 16:19:44 +0530 Subject: [PATCH] #3469: locked pinning clamps without f64::clamp The sub-pixel bounds lx + ix and lx + lw - ix round separately, so at third resolution they can still cross by an ulp and f64::clamp panics; a NaN layer size panicked too. max/min equals clamp whenever the bounds are ordered and cannot panic. The test now covers half and third resolution at fractional offsets and a NaN layer size. The parity note says Amount, not the displacement, is bounded to 2^24 px. --- crates/effects/src/distort2.rs | 19 ++++++++++++------- docs/effects-parity.md | 2 +- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/crates/effects/src/distort2.rs b/crates/effects/src/distort2.rs index 8ca2f2d72..24ffa3ab6 100644 --- a/crates/effects/src/distort2.rs +++ b/crates/effects/src/distort2.rs @@ -124,7 +124,8 @@ fn turbulent_displace(ctx: &EffectCtx, mut b: Buf) -> Buf { let (lx, ly, lw, lh) = layer_rect(ctx, &b); let edge = (lw.min(lh) * if locked { 0.25 } else { 0.1 }).max(1.0); // Locked: samples stay between the outermost pixel centres, or at the centre of a layer under - // a pixel across (half resolution), whose bounds would otherwise cross. + // a pixel across (a reduced resolution). Its bounds may still differ by rounding, so the + // clamp is max/min, which `f64::clamp` would panic on. let (ix, iy) = (0.5f64.min(lw * 0.5), 0.5f64.min(lh * 0.5)); let lock = (lx + ix, lx + lw - ix, ly + iy, ly + lh - iy); let seed = (ctx.seed ^ 0x7d15).wrapping_add((ctx.params.f("evolutionOptions/randomSeed") as i64 as u32).wrapping_mul(0x9e37_79b9)); @@ -173,7 +174,7 @@ fn turbulent_displace(ctx: &EffectCtx, mut b: Buf) -> Buf { }; let (sx, sy) = (x + dx * k, y + dy * k); if locked { - return Some((sx.clamp(lock.0, lock.1), sy.clamp(lock.2, lock.3))); + return Some((sx.max(lock.0).min(lock.1), sy.max(lock.2).min(lock.3))); } Some((sx, sy)) }); @@ -1077,8 +1078,9 @@ mod tests { } } - /// #3469: a locked pinning on a layer under a buffer pixel across (a 1-pixel layer at half - /// resolution) keeps samples inside it without inverted clamp bounds, at any Amount. + /// #3469: a locked pinning on a layer under a buffer pixel across (a 1-pixel layer at half or + /// third resolution, anywhere in the buffer) keeps samples inside it without its rounded + /// bounds crossing, at any Amount. #[test] fn turbulent_displace_locked_pinning_on_a_subpixel_layer_does_not_crash() { let spec = crate::find("ec.distort.turbulentdisplace").unwrap(); @@ -1086,9 +1088,12 @@ mod tests { let mut params = Params { values: spec.params.iter().map(|p| (p.id.to_string(), p.default.clone())).collect() }; params.values.insert("amount".into(), num(amount)); params.values.insert("pinning".into(), Value::Enum(8)); - let ctx = EffectCtx { params: ¶ms, time: 0.5, layer_size: [1.0, 1.0], seed: 3, adjustment: false, env: Default::default() }; - let o = crate::apply(spec, &ctx, Buf { img: test_img(1, 1), offset: [0.0, 0.0], scale: 0.5 }); - assert!(o.img.data.iter().all(|p| p.iter().all(|v| v.is_finite())), "{amount}"); + for (size, scale, offset) in [(1.0, 0.5, 0.0), (1.0, 1.0 / 3.0, -8.0), (1.0, 1.0 / 3.0, 7.0), (0.9, 1.0, -8.0), (f64::NAN, 1.0, 0.0)] { + let ctx = EffectCtx { params: ¶ms, time: 0.5, layer_size: [size, size], seed: 3, adjustment: false, env: Default::default() }; + let o = crate::apply(spec, &ctx, Buf { img: test_img(2, 2), offset: [offset, offset], scale }); + // A layer size that is not a number only has to render without panicking. + assert!(size.is_nan() || o.img.data.iter().all(|p| p.iter().all(|v| v.is_finite())), "{amount} {size} {scale} {offset}"); + } } } diff --git a/docs/effects-parity.md b/docs/effects-parity.md index d109da598..870a1ca49 100644 --- a/docs/effects-parity.md +++ b/docs/effects-parity.md @@ -64,7 +64,7 @@ the GPU is performance, not parity. | Date | Change | Summary | |---|---|---| -| 2026-11-17 | minor | Turbulent Displace: Amount takes After Effects' recorded valid range, −10000..10000 (default and the −200..200 slider unchanged). Past it (an expression's value) the displacement is bounded to 2^24 px and a NaN Amount leaves the layer unchanged, so padding and sampling stay finite (CPU and GPU). Locked pinning on a layer under a pixel across no longer crashes | +| 2026-11-17 | minor | Turbulent Displace: Amount takes After Effects' recorded valid range, −10000..10000 (default and the −200..200 slider unchanged). Past it (an expression's value) Amount is bounded to 2^24 px and a NaN Amount leaves the layer unchanged, so padding and sampling stay finite (CPU and GPU). Locked pinning on a layer under a pixel across no longer crashes | | 2026-11-12 | minor | Parameters take After Effects' recorded valid ranges (hard range; defaults and sliders unchanged): Levels (Individual Controls) levels −10000..10000 and Gamma from 0; 4-Color Gradient Blend to 10000 and Jitter to 500 %; Change Color Hue Transform ±1800°; Noise HLS (and Auto) amounts to 1000 % and Grain Size from 0; Grid Border to 2000; Venetian Blinds Width 1..32000 and Feather to 32000; Radial Wipe Feather to 32000; Scatter Amount to 1000; Beam thicknesses to 4000; Transform Scale ±30000 %; Turbulent Displace Random Seed to 100000. A test checks every mapped parameter's range against the recorded table (CPU and GPU) | | 2026-10-19 | minor | Glow (original colours): bright pass per channel, 8 × (value − threshold + 0.061), measured against After Effects 2026 (CPU and GPU) | | 2026-10-19 | minor | Glow (colour channels): the glow covers the layer's blurred alpha, blur σ = 0.384 × radius, measured against After Effects 2026 renders (CPU and GPU) |