forge
Explore
Log in

Don't you dare go Hollow

The undo stack stops at 100 steps and an export clones the timeline, not the session

Browse files at this commit

2504de71a38482fc5bc91df5cda5869f57b45aecAhmet Kaan GümüşParent: 734ca14
  • fix
    • the undo stack stops at 100 steps and an export clones the timeline, not the session
Show full message
🐛 fix(project): the undo stack stops at 100 steps and an export clones the timeline, not the session

snapshot() drops the oldest step at the cap: one gesture is one step, so 100 is
past any chain walked back by hand, and a 1394-clip jumpcut timeline's history is
a bounded ~10 MB instead of one that grows for as long as the session lasts.

export_to_with hands export::start a Project::export_snapshot() -- lanes and
sources with the history left behind. The clone is taken on the UI thread and an
export never walks the history back; the written bytes are unchanged.
crates/engine/src/playback.rsmodified+1 -1
@@ -2370,7 +2370,7 @@ impl PlaybackSession {
23702370 out: &Path,
23712371 settings: &crate::export::ExportSettings,
23722372 ) -> crate::ExportHandle {
2373- crate::export::start(self.project.clone(), self.meta, out, settings)
2373+ crate::export::start(self.project.export_snapshot(), self.meta, out, settings)
23742374 }
23752375
23762376 /// Moves the clock forward; the caller runs this once per rendered frame.
crates/engine/src/project.rsmodified+48 -1
@@ -618,6 +618,13 @@ pub type Parts = (
618618 Vec<ColorParams>,
619619 );
620620
621+/// How many undo steps a project keeps. One gesture is one step, so 100 is past
622+/// any chain a person walks back by hand, and the oldest step is dropped rather
623+/// than the history growing without end: a snapshot is the whole lane list, so
624+/// on a 1394-clip jumpcut timeline this is a bounded ~10 MB instead of a leak
625+/// that grows for as long as the session lasts.
626+const HISTORY_CAP: usize = 100;
627+
621628 /// The edit list plus its undo history.
622629 #[derive(Clone, Debug)]
623630 pub struct Project {
@@ -631,7 +638,8 @@ pub struct Project {
631638 /// The same, for [`Clip::color`].
632639 color: Vec<ColorParams>,
633640 /// Snapshots pushed *before* each successful edit; `undo` pops one. The
634- /// whole lane list, so adding a lane undoes as well.
641+ /// whole lane list, so adding a lane undoes as well. Bounded by
642+ /// [`HISTORY_CAP`]: at the cap the oldest step goes.
635643 history: Vec<Vec<LaneData>>,
636644 /// Never rolled back by an undo: an id retired by an undone split must not
637645 /// come back and group two clips that were never together.
@@ -2693,6 +2701,24 @@ impl Project {
26932701 }
26942702 }
26952703
2704+ /// The project an export renders from: everything a render reads, with the
2705+ /// undo history left behind. An export never walks the history back, and
2706+ /// cloning it costs a copy of every lane list in the session -- this is
2707+ /// taken on the UI thread, so it clones the lanes and the sources alone.
2708+ pub fn export_snapshot(&self) -> Self {
2709+ Self {
2710+ sources: self.sources.clone(),
2711+ lanes: self.lanes.clone(),
2712+ eq: self.eq.clone(),
2713+ color: self.color.clone(),
2714+ history: Vec::new(),
2715+ next_link: self.next_link,
2716+ subtitles: self.subtitles.clone(),
2717+ limiter: self.limiter,
2718+ tone: self.tone,
2719+ }
2720+ }
2721+
26962722 /// Half-open `(source, start, end)` segments in *source* seconds, from
26972723 /// `timeline_frame` to the end of the timeline -- the play list for the
26982724 /// audio worker, read off **`A1`**. A `None` source is a gap: the
@@ -2861,6 +2887,9 @@ impl Project {
28612887 /// Pushes the undo snapshot. Every mutating method calls this once, *after*
28622888 /// it has decided it will succeed -- a refusal must not cost an undo step.
28632889 fn snapshot(&mut self) {
2890+ if self.history.len() == HISTORY_CAP {
2891+ self.history.remove(0);
2892+ }
28642893 self.history.push(self.lanes.clone());
28652894 }
28662895
@@ -4215,6 +4244,24 @@ mod tests {
42154244 assert_eq!(shape(&p)[0], vec![clip(0, 0, 9, 0)]);
42164245 }
42174246
4247+ /// Past the cap the *oldest* step goes, so a long session undoes exactly
4248+ /// `HISTORY_CAP` gestures and then runs dry -- it does not grow for ever.
4249+ #[test]
4250+ fn history_stops_at_the_cap() {
4251+ let mut p = Project::single(FILE, 400);
4252+ for frame in 1..=150 {
4253+ assert!(p.split(frame), "split {frame} is an edit");
4254+ }
4255+ assert_eq!(p.history.len(), HISTORY_CAP, "and only the last 100 kept");
4256+ for step in 0..HISTORY_CAP {
4257+ assert!(p.undo(), "undo {step} is inside the cap");
4258+ }
4259+ assert!(!p.undo(), "and the 101st has nothing left to take");
4260+ // 100 undos off 150 splits is the timeline after the 50th: the older
4261+ // steps were dropped, not the newer ones.
4262+ assert_eq!(p.clips().len(), 51);
4263+ }
4264+
42184265 /// Undo/redo by hand across a split must never merge two takes into one
42194266 /// group by reusing an id.
42204267 #[test]