FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust
NEST1: a sequence can never contain itself
justjohn1234529d9d0ac5a34
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rsindex c6f90e52a..636cc9ec6 100644--- a/crates/engine/src/lib.rs+++ b/crates/engine/src/lib.rs@@ -681,11 +681,25 @@ impl Session {commands::find(id).is_some_and(|c| (c.enabled)(self).is_ok())}+ /// Every edit passes through here: one that would put a sequence inside itself (directly or+ /// through another nested sequence) is refused, whichever command asked for it. A project that+ /// was opened with such a sequence already in it can still be edited (and repaired).+ fn refuse_self_nesting(&self, edited: &Project) -> Result<()> {+ match edited.nest_cycle() {+ Some(id) if self.project.nest_cycle().is_none() => {+ let name = edited.item(id).map(|i| i.name.as_str()).unwrap_or_default();+ Err(EngineError::Other(format!("a sequence cannot be nested inside itself (\u{201c}{name}\u{201d})")))+ }+ _ => Ok(()),+ }+ }+/// Apply an undoable project edit. The closure gets a mutable copy; on error nothing changes.pub fn edit<R>(&mut self, label: &str, f: impl FnOnce(&mut Project, &mut EditorState) -> Result<R>) -> Result<R> {let mut p = (*self.project).clone();let mut st = self.state.clone();let r = f(&mut p, &mut st)?;+ self.refuse_self_nesting(&p)?;let old = std::mem::replace(&mut self.project, Arc::new(p));self.history.undo.push((label.to_string(), old));if self.history.undo.len() > self.history.limit {@@ -710,6 +724,7 @@ impl Session {let mut p = (*self.project).clone();let mut st = self.state.clone();let r = f(&mut p, &mut st)?;+ self.refuse_self_nesting(&p)?;self.project = Arc::new(p);self.state = st;self.bump();@@ -936,6 +951,8 @@ mod mixer_tests;#[cfg(test)]mod multicam_tests;#[cfg(test)]+mod nesting_tests;+#[cfg(test)]mod panels_tests;#[cfg(test)]mod presets_tests;diff --git a/crates/engine/src/nesting_tests.rs b/crates/engine/src/nesting_tests.rsnew file mode 100644index 000000000..7a3f3ba6c--- /dev/null+++ b/crates/engine/src/nesting_tests.rs@@ -0,0 +1,102 @@+//! Nested sequences: a sequence can never contain itself, whichever+//! command is asked to put it there, and Nest… keeps what was selected.++use super::*;+use filmcraft_project::TrackKind;+use filmcraft_time::TimeRange;+use serde_json::json;++fn demo() -> Session {+ let mut s = Session::default();+ s.execute("file.openDemoProject", json!({})).unwrap();+ s+}++fn clip_ids(s: &Session, kind: TrackKind, idx: usize) -> Vec<u64> {+ s.active_sequence().unwrap().tracks(kind)[idx].items.iter().map(|i| i.id.0).collect()+}++/// Nest the second V1 clip of the active sequence; returns (outer sequence, nested sequence).+fn nest_one(s: &mut Session, name: &str) -> (ItemId, ItemId) {+ let outer = s.state.active_sequence.unwrap();+ let v = clip_ids(s, TrackKind::Video, 0)[1];+ s.execute("timeline.select", json!({"clips": [v]})).unwrap();+ let r = s.execute("clip.nest", json!({"name": name})).unwrap();+ (outer, ItemId(r["sequence"].as_u64().unwrap()))+}++/// The command fails with the self-nesting message and changes nothing (project and undo history).+fn refused(s: &mut Session, command: &str, params: serde_json::Value) {+ let (before, undo) = (s.project.clone(), s.history.undo.len());+ let e = s.execute(command, params).expect_err(command).to_string();+ assert!(e.contains("cannot be nested inside itself"), "{command}: {e}");+ assert!(Arc::ptr_eq(&before, &s.project), "{command} left the project alone");+ assert_eq!(s.history.undo.len(), undo, "{command} added no undo step");+ assert_eq!(s.project.nest_cycle(), None);+}++#[test]+fn a_sequence_cannot_be_placed_in_itself() {+ let mut s = demo();+ let a = s.state.active_sequence.unwrap();+ refused(&mut s, "timeline.place", json!({"item": a.0, "seconds": 1.0}));+ refused(&mut s, "timeline.place", json!({"item": a.0, "seconds": 1.0, "insert": true}));+ // from the Source monitor as well+ s.execute("source.open", json!({"item": a.0})).unwrap();+ refused(&mut s, "source.insert", json!({}));+ refused(&mut s, "source.overwrite", json!({}));+}++#[test]+fn a_sequence_cannot_be_placed_in_a_sequence_it_contains() {+ let mut s = demo();+ let (outer, nested) = nest_one(&mut s, "Inner");+ // outer holds Inner: Inner cannot take outer, nor itself+ s.execute("sequence.open", json!({"item": nested.0})).unwrap();+ refused(&mut s, "timeline.place", json!({"item": outer.0, "seconds": 0.0}));+ refused(&mut s, "timeline.place", json!({"item": nested.0, "seconds": 0.0}));+ // one level further: a third sequence that holds outer cannot go into Inner either+ s.execute("sequence.open", json!({"item": outer.0})).unwrap();+ let third = ItemId(s.execute("file.newSequence", json!({"name": "Third"})).unwrap()["sequence"].as_u64().unwrap());+ s.execute("sequence.open", json!({"item": third.0})).unwrap();+ s.execute("timeline.place", json!({"item": outer.0, "seconds": 0.0})).expect("a nest of a nest is fine");+ s.execute("sequence.open", json!({"item": nested.0})).unwrap();+ refused(&mut s, "timeline.place", json!({"item": third.0, "seconds": 0.0}));+ // the other direction stays allowed+ s.execute("sequence.open", json!({"item": third.0})).unwrap();+ s.execute("timeline.place", json!({"item": nested.0, "seconds": 30.0})).expect("Inner may be used twice");+}++#[test]+fn pasting_a_nest_into_its_own_sequence_is_refused() {+ let mut s = demo();+ let (_, nested) = nest_one(&mut s, "Inner");+ // copy the nest clip (selected by Nest…), open the nested sequence and paste it there+ s.execute("edit.copy", json!({})).unwrap();+ s.execute("sequence.open", json!({"item": nested.0})).unwrap();+ refused(&mut s, "edit.paste", json!({}));+ refused(&mut s, "edit.pasteInsert", json!({}));+}++#[test]+fn a_project_opened_with_a_cycle_can_still_be_edited_and_repaired() {+ let mut s = demo();+ let a = s.state.active_sequence.unwrap();+ // what a damaged project file would hold: the sequence on its own track+ let mut p = (*s.project).clone();+ let rate = p.sequence(a).unwrap().settings.frame_rate;+ let it = p.make_track_item(a, TrackKind::Video, Tick(900 * filmcraft_time::TICKS_PER_SECOND), TimeRange::new(Tick::ZERO, rate.tick_of(24)), rate).unwrap();+ let bad = it.id;+ p.sequence_mut(a).unwrap().video_tracks[0].items.push(it);+ s.project = Arc::new(p);+ assert_eq!(s.project.nest_cycle(), Some(a));+ // unrelated edits still work+ let first = clip_ids(&s, TrackKind::Video, 0)[0];+ s.execute("timeline.select", json!({"clips": [first]})).unwrap();+ s.execute("clip.enable", json!({})).expect("edits are not locked out");+ // and removing the clip repairs it, after which the guard is back+ s.execute("timeline.select", json!({"clips": [bad.0]})).unwrap();+ s.execute("edit.clear", json!({})).unwrap();+ assert_eq!(s.project.nest_cycle(), None);+ refused(&mut s, "timeline.place", json!({"item": a.0, "seconds": 1.0}));+}diff --git a/crates/project/src/lib.rs b/crates/project/src/lib.rsindex 692ce4323..94be2d898 100644--- a/crates/project/src/lib.rs+++ b/crates/project/src/lib.rs@@ -1198,6 +1198,49 @@ impl Project {self.items.values().filter(|i| matches!(i.kind, ItemKind::Sequence(_)))}+ /// A sequence that contains itself, directly or through the sequences nested in it (the lowest+ /// id of those on a cycle), or `None` when nesting is sound. Such a sequence has no frame to+ /// show, so edits that would make one are refused; only a damaged project file holds one.+ pub fn nest_cycle(&self) -> Option<ItemId> {+ // each sequence's nested sequences+ let mut nests: BTreeMap<ItemId, Vec<ItemId>> = BTreeMap::new();+ for it in self.items.values() {+ let ItemKind::Sequence(q) = &it.kind else { continue };+ let mut inner: Vec<ItemId> = q.all_tracks().flat_map(|t| t.items.iter().map(|i| i.item)).filter(|i| self.sequence(*i).is_some()).collect();+ inner.sort_unstable();+ inner.dedup();+ if !inner.is_empty() {+ nests.insert(it.id, inner);+ }+ }+ // drop sequences whose nests all lead out of the set, until none can be dropped: what is+ // left lies on a cycle or leads into one+ loop {+ let leaves: Vec<ItemId> = nests.iter().filter(|(_, inner)| inner.iter().all(|i| !nests.contains_key(i))).map(|(id, _)| *id).collect();+ if leaves.is_empty() {+ break;+ }+ for id in leaves {+ nests.remove(&id);+ }+ }+ // of those, the ones that can reach themselves+ nests.keys().copied().find(|start| {+ let mut seen: Vec<ItemId> = Vec::new();+ let mut todo: Vec<ItemId> = nests.get(start).cloned().unwrap_or_default();+ while let Some(id) = todo.pop() {+ if id == *start {+ return true;+ }+ if !seen.contains(&id) {+ seen.push(id);+ todo.extend(nests.get(&id).into_iter().flatten().copied());+ }+ }+ false+ })+ }+/// Create an empty sequence with `v` video and `a` audio tracks.pub fn new_sequence(&mut self, name: &str, settings: SequenceSettings, v: usize, a: usize, bin: Option<BinId>) -> ItemId {let mut seq = Sequence {@@ -1609,4 +1652,34 @@ mod tests {assert!(p.root.remove_item(i));assert_eq!(p.root.parent_of(i), None);}++ #[test]+ fn nest_cycle_finds_sequences_that_contain_themselves() {+ let (mut p, clip, a) = demo_project();+ let rate = p.sequence(a).unwrap().settings.frame_rate;+ let b = p.new_sequence("b", SequenceSettings::default(), 1, 1, None);+ let c = p.new_sequence("c", SequenceSettings::default(), 1, 1, None);+ let put = |p: &mut Project, outer: ItemId, inner: ItemId| {+ let it = p.make_track_item(inner, TrackKind::Video, Tick::ZERO, TimeRange::new(Tick::ZERO, rate.tick_of(10)), rate).unwrap();+ let id = it.id;+ p.sequence_mut(outer).unwrap().video_tracks[0].items.push(it);+ id+ };+ // media and a chain of nests (a in b in c, a twice in c) are sound+ put(&mut p, a, clip);+ put(&mut p, b, a);+ put(&mut p, c, b);+ put(&mut p, c, a);+ assert_eq!(p.nest_cycle(), None);+ // c inside a closes the loop a → c → b → a+ let closing = put(&mut p, a, c);+ assert_eq!(p.nest_cycle(), Some(a));+ p.sequence_mut(a).unwrap().video_tracks[0].items.retain(|i| i.id != closing);+ assert_eq!(p.nest_cycle(), None);+ // a sequence directly inside itself; one that only leads into the loop is not reported+ put(&mut p, c, c);+ let d = p.new_sequence("d", SequenceSettings::default(), 1, 1, None);+ put(&mut p, d, c);+ assert_eq!(p.nest_cycle(), Some(c));+ }}diff --git a/crates/render/src/audio.rs b/crates/render/src/audio.rsindex e797a8054..794e12e25 100644--- a/crates/render/src/audio.rs+++ b/crates/render/src/audio.rs@@ -80,9 +80,25 @@ pub fn track_input_live(sr: u32,sources: &dyn SourceProvider,ovs: &HashMap<(TrackId, String), Override>,+) -> AudioBuffer {+ track_input_at(project, track, start, frames, sr, sources, ovs, 0)+}++/// [`track_input_live`] for a track `depth` nested sequences down from the one being mixed.+#[allow(clippy::too_many_arguments)]+pub(crate) fn track_input_at(+ project: &Project,+ track: &Track,+ start: i64,+ frames: usize,+ sr: u32,+ sources: &dyn SourceProvider,+ ovs: &HashMap<(TrackId, String), Override>,+ depth: u32,) -> AudioBuffer {let w = crate::mixer::width_of(track.channels);- let live = ClipLive { vol: ovs.get(&(track.id, CLIP_LANE_VOLUME.to_string())).copied(), pan: ovs.get(&(track.id, CLIP_LANE_PAN.to_string())).copied() };+ let live =+ ClipLive { vol: ovs.get(&(track.id, CLIP_LANE_VOLUME.to_string())).copied(), pan: ovs.get(&(track.id, CLIP_LANE_PAN.to_string())).copied(), depth };let range = TimeRange::from_bounds(Tick::from_units(start, sr as i64), Tick::from_units(start + frames as i64, sr as i64));let mut tbuf = AudioBuffer::silence(sr, w, frames);for item in track.items.iter().filter(|i| i.enabled && i.range().overlaps(&range)) {@@ -132,6 +148,8 @@ pub fn track_input_live(struct ClipLive {vol: Option<Override>,pan: Option<Override>,+ /// How many nested sequences deep this track is ([`crate::MAX_NEST_DEPTH`] ends the descent).+ depth: u32,}/// Balance for stereo signals (clip Panner, stereo track pan): centre = unity on both sides, turning@@ -168,7 +186,7 @@ fn mix_item(let w = out.channels.len();let n = (a1 - a0) as usize;let buf = if let Some(nested) = project.sequence(item.item) {- nested_audio(project, item, nested, a0, n, sr, sources, w)+ nested_audio(project, item, nested, a0, n, sr, sources, w, live.depth)} else {let Some(src) = sources.source(item.item) else { return };if !src.info().has_audio() {@@ -227,16 +245,32 @@ fn mix_item(/// A nested sequence's mix for timeline samples `[a0, a0 + n)` of the clip that shows it, at width/// `w`. A multi-camera clip plays the audio of its source's audio setting: camera 1, all cameras,-/// or (when switching audio) the angle the clip selects.+/// or (when switching audio) the angle the clip selects. `depth` is the nesting depth of the clip's+/// own sequence: past [`crate::MAX_NEST_DEPTH`] the nest is silent, like its picture is empty, so a+/// sequence that contains itself (a damaged project; the editor refuses to make one) cannot+/// recurse without end.#[allow(clippy::too_many_arguments)]-fn nested_audio(project: &Project, item: &TrackItem, nested: &Sequence, a0: i64, n: usize, sr: u32, sources: &dyn SourceProvider, w: usize) -> Vec<Vec<f32>> {+fn nested_audio(+ project: &Project,+ item: &TrackItem,+ nested: &Sequence,+ a0: i64,+ n: usize,+ sr: u32,+ sources: &dyn SourceProvider,+ w: usize,+ depth: u32,+) -> Vec<Vec<f32>> {+ if depth >= crate::MAX_NEST_DEPTH {+ return vec![vec![0.0; n]; w];+ }let rel0 = a0 - item.start.to_units_floor(sr as i64) + item.source_in.to_units_floor(sr as i64);let q = if nested.multicam.is_some() {std::borrow::Cow::Owned(nested.with_angle_audio(item.multicam_angle(nested)))} else {std::borrow::Cow::Borrowed(nested)};- let b = crate::mixer::mix_graph(project, &q, rel0, n, sources, None);+ let b = crate::mixer::mix_graph_at(project, &q, rel0, n, sources, None, depth + 1);let mut v = to_layout(b, Layout::from_channels(w), Mixdown::FrontRear).channels;v.resize(w, vec![0.0; n]);vdiff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rsindex db136e769..d6f557b5d 100644--- a/crates/render/src/lib.rs+++ b/crates/render/src/lib.rs@@ -54,13 +54,18 @@ impl<F: Fn(ItemId) -> Option<SharedSource> + Sync> SourceProvider for F {}}+/// How many nested sequences deep the picture and the sound are followed. Deeper nests draw+/// nothing and are silent, which also ends a sequence that contains itself (only a damaged project+/// has one: the editor refuses the edit).+pub const MAX_NEST_DEPTH: u32 = 8;+#[derive(Clone, Copy, Debug)]pub struct RenderOptions {/// Output scale relative to the sequence frame size (1.0 = full, 0.5 = ½ resolution…).pub scale: f32,/// Skip standard effects (fast scrubbing / "Toggle Effects" off).pub effects: bool,- /// Nesting depth guard.+ /// Nesting depth guard (see [`MAX_NEST_DEPTH`]).pub depth: u32,/// Draw the sequence's visible caption tracks over the picture (Program monitor, burn-in on/// export). Never applies to nested sequences.@@ -96,7 +101,7 @@ fn render_seq(project: &Project, seq: &Sequence, t: Tick, opts: RenderOptions, spub(crate) fn render_seq_tracks(project: &Project, seq: &Sequence, t: Tick, opts: RenderOptions, sources: &dyn SourceProvider, only: Option<usize>) -> Image {let (w, h) = output_size(seq, opts.scale);let mut canvas = Image::new(w, h);- if opts.depth > 8 {+ if opts.depth > MAX_NEST_DEPTH {return canvas;}let tc = format_time(t, seq.settings.frame_rate, seq.settings.drop_frame, TimeDisplay::Timecode, seq.settings.sample_rate as i64);diff --git a/crates/render/src/mixer.rs b/crates/render/src/mixer.rsindex a142768b7..91479ede0 100644--- a/crates/render/src/mixer.rs+++ b/crates/render/src/mixer.rs@@ -53,7 +53,7 @@ use filmcraft_time::Tick;use rayon::prelude::*;use crate::SourceProvider;-use crate::audio::{pan_gains, track_input_live};+use crate::audio::{pan_gains, track_input_at};use crate::audio_fx::{Mapping, mapping};/// Strip id of the Mix (master) track in [`LiveMix`] and commands.@@ -830,6 +830,20 @@ fn run_strip(plan: &Plan, si: usize, st: &mut StripState, mut buf: Bus, x0: i64,/// Mix's width (2 channels, or 6 in L, R, C, LFE, Ls, Rs order for a 5.1 Mix). `live` adds the UI's/// held controls and receives the meters.pub fn mix_graph(project: &Project, seq: &Sequence, start: i64, frames: usize, sources: &dyn SourceProvider, live: Option<&LiveMix>) -> AudioBuffer {+ mix_graph_at(project, seq, start, frames, sources, live, 0)+}++/// [`mix_graph`] for a sequence `depth` nests down from the one being mixed (see+/// [`crate::MAX_NEST_DEPTH`]).+pub(crate) fn mix_graph_at(+ project: &Project,+ seq: &Sequence,+ start: i64,+ frames: usize,+ sources: &dyn SourceProvider,+ live: Option<&LiveMix>,+ depth: u32,+) -> AudioBuffer {let sr = seq.settings.sample_rate.max(1);let ovs = live.filter(|l| l.is_active()).map(LiveMix::overrides).unwrap_or_default();let plan = Plan::build(seq, &ovs);@@ -870,7 +884,7 @@ pub fn mix_graph(project: &Project, seq: &Sequence, start: i64, frames: usize, sreturn None;}let input = if has_clips {- let mut v = track_input_live(project, &s.track, x0, total, sr, sources, &ovs).channels;+ let mut v = track_input_at(project, &s.track, x0, total, sr, sources, &ovs, depth).channels;v.resize(s.width, vec![0.0; total]);v} else {diff --git a/crates/render/src/mixer_tests.rs b/crates/render/src/mixer_tests.rsindex 54f064743..c76481dd3 100644--- a/crates/render/src/mixer_tests.rs+++ b/crates/render/src/mixer_tests.rs@@ -608,3 +608,23 @@ fn pan51_automation_is_block_invariant() {assert!(energy(0, 0, 2000) > 5.0 * energy(1, 0, 2000));assert!(energy(1, 10_000, 12_000) > 5.0 * energy(0, 10_000, 12_000));}++/// A damaged project can hold a sequence that contains itself (the editor refuses to make one).+/// Mixing it must end: this used to recurse until the stack overflowed.+#[test]+fn a_sequence_nested_in_itself_mixes_to_an_end() {+ let mut p = Project::new("cycle");+ let a = p.new_sequence("a", SequenceSettings::default(), 1, 1, None);+ let b = p.new_sequence("b", SequenceSettings::default(), 1, 1, None);+ let rate = FrameRate::default();+ let second = TimeRange::new(Tick::ZERO, Tick(TICKS_PER_SECOND));+ // a holds itself and b; b holds a+ for (outer, inner) in [(a, a), (a, b), (b, a)] {+ let it = p.make_track_item(inner, TrackKind::Audio, Tick::ZERO, second, rate).unwrap();+ p.sequence_mut(outer).unwrap().audio_tracks[0].items.push(it);+ }+ let seq = p.sequence(a).unwrap();+ let out = mix_graph(&p, seq, 0, 4800, &SourceMap::default(), None);+ assert_eq!(out.channels.len(), 2);+ assert!(out.channels.iter().all(|c| c.len() == 4800 && c.iter().all(|s| *s == 0.0)), "no source: silence");+}diff --git a/crates/render/src/plan.rs b/crates/render/src/plan.rsindex 073f831cb..3b6e2de71 100644--- a/crates/render/src/plan.rs+++ b/crates/render/src/plan.rs@@ -142,16 +142,16 @@ pub fn plan_frame(project: &Project, seq_id: ItemId, t: Tick, opts: RenderOptionlayers.push(PlanLayer::new(Arc::new(VideoFrame::rgba_f32(1, 1, col.to_vec())), Affine::scale(w as f64, h as f64), 1.0, Blend::Normal));let (it, k) = if p < 0.5 { (a, 1.0 - p * 2.0) } else { (b, (p - 0.5) * 2.0) };if let Some(it) = it {- push_item(project, seq, it, t, opts, sources, k, Some(Blend::Normal), &mut layers);+ push_item(project, seq, it, t, opts, sources, k, Some(Blend::Normal), 0, &mut layers);}}_ => {// cross dissolve: A at full, B over it at p (premultiplied over == linear mix when A is opaque)if let Some(it) = a {- push_item(project, seq, it, t, opts, sources, 1.0 - if b.is_none() { p } else { 0.0 }, Some(Blend::Normal), &mut layers);+ push_item(project, seq, it, t, opts, sources, 1.0 - if b.is_none() { p } else { 0.0 }, Some(Blend::Normal), 0, &mut layers);}if let Some(it) = b {- push_item(project, seq, it, t, opts, sources, p, Some(Blend::Normal), &mut layers);+ push_item(project, seq, it, t, opts, sources, p, Some(Blend::Normal), 0, &mut layers);}}}@@ -161,7 +161,7 @@ pub fn plan_frame(project: &Project, seq_id: ItemId, t: Tick, opts: RenderOptionif !item.enabled {continue;}- push_item(project, seq, item, t, opts, sources, 1.0, None, &mut layers);+ push_item(project, seq, item, t, opts, sources, 1.0, None, 0, &mut layers);}if opts.captions {for o in crate::caption_overlays(seq, t, w, h) {@@ -178,6 +178,8 @@ pub fn plan_frame(project: &Project, seq_id: ItemId, t: Tick, opts: RenderOption/// Push the layer(s) of `item`. `blend` overrides the item's own blend mode: inside a transition/// the CPU reference mixes the clips and composites the result Normal, ignoring their modes.+/// `nest` counts the multi-camera clips already followed to reach `item` (see+/// [`crate::MAX_NEST_DEPTH`]).#[allow(clippy::too_many_arguments)]fn push_item(project: &Project,@@ -188,6 +190,7 @@ fn push_item(sources: &dyn SourceProvider,extra_opacity: f32,blend: Option<Blend>,+ nest: u32,out: &mut Vec<PlanLayer>,) {// frame time (`ft`) vs. effect time (`mt`): they differ inside a frame hold without Hold Filters@@ -198,6 +201,7 @@ fn push_item(// A multi-camera clip that only shows its angle (no effects, untransformed, same frame size)// draws the angle's clip directly: no CPU pass over the nested sequence.if let Some(ItemKind::Sequence(nested)) = project.item(item.item).map(|p| &p.kind)+ && nest < crate::MAX_NEST_DEPTH&& let Some(angle) = item.multicam_angle(nested)&& !(opts.effects && item.has_standard_effects())&& (nested.settings.width, nested.settings.height) == (seq.settings.width, seq.settings.height)@@ -209,7 +213,7 @@ fn push_item(// Inside the nested sequence the angle's clip is composited onto an empty canvas, where// every mode but Dissolve is Normal; the multicam clip's own mode then applies to it.if let Some(inner) = tr.item_at(ft).filter(|i| i.enabled) {- push_item(project, nested, inner, ft, opts, sources, extra_opacity * op, Some(bl), out);+ push_item(project, nested, inner, ft, opts, sources, extra_opacity * op, Some(bl), nest + 1, out);}return;}diff --git a/crates/render/src/tests.rs b/crates/render/src/tests.rsindex 4489447d8..20ec4fefb 100644--- a/crates/render/src/tests.rs+++ b/crates/render/src/tests.rs@@ -350,3 +350,22 @@ fn draft_reduced_resolution_plans_carry_decimated_yuv() {}}}++/// A damaged project can hold a multi-camera clip whose angle is the clip itself. Planning and+/// rendering its frame must end: the plan's multi-camera shortcut used to recurse until the stack+/// overflowed.+#[test]+fn a_multicam_clip_showing_itself_plans_and_renders_to_an_end() {+ let mut p = Project::new("cycle");+ let a = p.new_sequence("a", SequenceSettings::default(), 1, 0, None);+ let rate = FrameRate::default();+ let mut it = p.make_track_item(a, TrackKind::Video, Tick::ZERO, TimeRange::new(Tick::ZERO, Tick(TICKS_PER_SECOND)), rate).unwrap();+ it.multicam = Some(filmcraft_project::multicam::MulticamSel { enabled: true, angle: 0 });+ p.sequence_mut(a).unwrap().video_tracks[0].items.push(it);+ let opts = RenderOptions { scale: 0.1, ..Default::default() };+ let sources = SourceMap::default();+ let img = plan::execute_cpu(&plan::plan_frame(&p, a, Tick::ZERO, opts, &sources));+ assert!(img.w > 0 && img.h > 0);+ let img = render_sequence(&p, a, Tick::ZERO, opts, &sources);+ assert!(img.w > 0 && img.h > 0);+}