Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

fix: same-tick echo commits reached the engine empty

Jareerac7b2b64e5ef
diff --git a/desktop/src/hooks/useEngineSession.ts b/desktop/src/hooks/useEngineSession.ts
index d4227ed6..236dd16b 100644
--- a/desktop/src/hooks/useEngineSession.ts
+++ b/desktop/src/hooks/useEngineSession.ts
@@ -131,12 +131,25 @@ export function useEngineSession({
// ── the gesture echo ─────────────────────────────────────────────────────
- /** Live: merges a patch into the echo for one clip. */
+ /**
+ * Live: merges a patch into the echo for one clip.
+ *
+ * The merge goes through `echoRef` and lands in it synchronously, not just
+ * through a state updater: a discrete control - adding an effect, picking
+ * a transition - echoes and commits in the same tick, and a commit that
+ * read the ref before the next render would see the world without the
+ * change it is supposed to commit. The engine never hearing about an
+ * applied effect is exactly how the paused monitor ends up showing the
+ * unprocessed frame.
+ */
const liveClip = useCallback((clipId: string, patch: Partial<Clip>) => {
- setEcho((current) => ({
+ const current = echoRef.current;
+ const next = {
...(current ?? {}),
[clipId]: { ...(current?.[clipId] ?? {}), ...patch },
- }));
+ };
+ echoRef.current = next;
+ setEcho(next);
}, []);
/**
diff --git a/engine/crates/wolfcut-export/src/lib.rs b/engine/crates/wolfcut-export/src/lib.rs
index 355c29fb..b8a97888 100644
--- a/engine/crates/wolfcut-export/src/lib.rs
+++ b/engine/crates/wolfcut-export/src/lib.rs
@@ -955,6 +955,29 @@ mod tests {
&bytes[centre..centre + 4],
);
+ // A clip with an effect chain: the paused monitor must show the
+ // processed pixels, not the raw decode. Negating red footage has to
+ // come back cyan-ish.
+ let mut effected = clip("video", 0, 0.0, 1.0, 0.0);
+ effected.path = path.to_string_lossy().into_owned();
+ effected.media_width = Some(64);
+ effected.media_height = Some(64);
+ effected.video_filter_chain = "negate".to_owned();
+ let filtered = PreviewFrameRequest {
+ time: 0.5,
+ width: 64,
+ height: 64,
+ rate_num: 30,
+ rate_den: 1,
+ clips: vec![effected],
+ };
+ let bytes = preview_frame(&mut pool, &filtered).expect("previews with a chain");
+ assert!(
+ bytes[centre] < 90 && bytes[centre + 1] > 120,
+ "the chain must be baked into the paused frame, got {:?}",
+ &bytes[centre..centre + 4],
+ );
+
let _ = std::fs::remove_file(&path);
}