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 {
2370 out: &Path,2370 out: &Path,
2371 settings: &crate::export::ExportSettings,2371 settings: &crate::export::ExportSettings,
2372 ) -> crate::ExportHandle {2372 ) -> 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)
2374 }2374 }
2375 2375
2376 /// Moves the clock forward; the caller runs this once per rendered frame.2376 /// 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 = (
618 Vec<ColorParams>,618 Vec<ColorParams>,
619 );619 );
620 620
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+
621 /// The edit list plus its undo history.628 /// The edit list plus its undo history.
622 #[derive(Clone, Debug)]629 #[derive(Clone, Debug)]
623 pub struct Project {630 pub struct Project {
@@ -631,7 +638,8 @@ pub struct Project {
631 /// The same, for [`Clip::color`].638 /// The same, for [`Clip::color`].
632 color: Vec<ColorParams>,639 color: Vec<ColorParams>,
633 /// Snapshots pushed *before* each successful edit; `undo` pops one. The640 /// 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.
635 history: Vec<Vec<LaneData>>,643 history: Vec<Vec<LaneData>>,
636 /// Never rolled back by an undo: an id retired by an undone split must not644 /// Never rolled back by an undo: an id retired by an undone split must not
637 /// come back and group two clips that were never together.645 /// come back and group two clips that were never together.
@@ -2693,6 +2701,24 @@ impl Project {
2693 }2701 }
2694 }2702 }
2695 2703
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+
2696 /// Half-open `(source, start, end)` segments in *source* seconds, from2722 /// Half-open `(source, start, end)` segments in *source* seconds, from
2697 /// `timeline_frame` to the end of the timeline -- the play list for the2723 /// `timeline_frame` to the end of the timeline -- the play list for the
2698 /// audio worker, read off **`A1`**. A `None` source is a gap: the2724 /// audio worker, read off **`A1`**. A `None` source is a gap: the
@@ -2861,6 +2887,9 @@ impl Project {
2861 /// Pushes the undo snapshot. Every mutating method calls this once, *after*2887 /// Pushes the undo snapshot. Every mutating method calls this once, *after*
2862 /// it has decided it will succeed -- a refusal must not cost an undo step.2888 /// it has decided it will succeed -- a refusal must not cost an undo step.
2863 fn snapshot(&mut self) {2889 fn snapshot(&mut self) {
2890+ if self.history.len() == HISTORY_CAP {
2891+ self.history.remove(0);
2892+ }
2864 self.history.push(self.lanes.clone());2893 self.history.push(self.lanes.clone());
2865 }2894 }
2866 2895
@@ -4215,6 +4244,24 @@ mod tests {
4215 assert_eq!(shape(&p)[0], vec![clip(0, 0, 9, 0)]);4244 assert_eq!(shape(&p)[0], vec![clip(0, 0, 9, 0)]);
4216 }4245 }
4217 4246
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+
4218 /// Undo/redo by hand across a split must never merge two takes into one4265 /// Undo/redo by hand across a split must never merge two takes into one
4219 /// group by reusing an id.4266 /// group by reusing an id.
4220 #[test]4267 #[test]