fix(core): a motion blur worker starting mid-film keeps the right state

The mover scan walks the whole film with callbacks live, then seeks back to
the worker's start. GSAP fires one-off calls in both directions, so a worker
starting between two calls took the later call's state and held it until the
next call. Going through 0 first gives every worker what frame 0 sees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vance Ingalls
2026-11-01 16:49:08 -08:00
co-authored by Claude Opus 5.5
parent 7c5c1ce849
commit a5e397a96d
2 changed files with 24 additions and 0 deletions
@@ -1038,6 +1038,28 @@ describe("painting", () => {
expect(reads.every(([, suppress]) => suppress === false)).toBe(true);
});
it("leaves a worker starting mid-film the state of the calls behind it, not ahead of it", () => {
installHtmlInCanvas();
const { h } = movingHost({ "data-motion-blur": "on", "data-motion-blur-events": "on" });
const calls = [
{ at: 0.3, text: "first" },
{ at: 0.7, text: "second" },
];
let head = 0;
let text = "";
// GSAP fires a one-off call on a loud crossing in either direction.
const seek = (t: number, suppress: boolean) => {
h.seek(t, suppress);
const crossed = calls.filter(({ at }) => Math.min(head, t) < at && at <= Math.max(head, t));
if (t < head) crossed.reverse();
if (!suppress) for (const call of crossed) text = call.text;
head = t;
};
initCaptureMotionBlur({ ...h, seek });
void paintCaptureMotionBlur(0.5, PLAY);
expect(text).toBe("first");
});
it("fires timeline callbacks during discovery only when the root allows events", () => {
for (const events of [true, false]) {
installHtmlInCanvas();
@@ -254,6 +254,8 @@ function createInstance(host: CaptureMotionBlurHost, config: Config, form: HtmlI
events: config.events,
onStep: (i, steps) => defects.sample(i, steps, (i / steps) * duration),
});
// Through 0, or a call behind restoreTo keeps the state the scan left. Workers start anywhere.
seek(0);
seek(restoreTo);
readEvents = found.readEvents;
scanDefect = defects.result();