diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 21be86b..806c809 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -1553,7 +1553,10 @@ impl Player { return; }; // An emptied timeline is a timeline; it is simply not a file. Refused by - // name here rather than written as a project of no frames. + // name here rather than written as a project of no frames -- and the + // engine refuses it again on the worker (`export::start`), so a caller + // that is not this button cannot get past it either. Two fences on + // purpose: this one is the one with a keystroke to blame. if session.is_empty() { self.notice = Some("NOTHING TO EXPORT — the timeline is empty".into()); cx.notify(); diff --git a/crates/engine/src/export.rs b/crates/engine/src/export.rs index 62a343f..b626490 100644 --- a/crates/engine/src/export.rs +++ b/crates/engine/src/export.rs @@ -165,7 +165,18 @@ pub fn start( // The rename is the last step and the only one that publishes a file // under the name the caller asked for; it stays on the same directory, // so it is atomic. + // + // An emptied timeline is a legal project and an illegal file: no + // picture, no sound, and a muxer that is never created because no coded + // frame arrives. Refused by name here -- before the format is even + // looked at, so an mp4 and a WAV refuse in the same words -- rather than + // left to write a file of no frames that nothing opens. Every caller of + // `start` comes through this, the app's own door + // (`PlaybackSession::is_empty`) being only the first fence. let written = match settings.format { + _ if project.timeline_frames() == 0 => { + Err("the timeline is empty: there is nothing to export".into()) + } Format::Mp4 => run(&project, &meta, &part, &worker, &settings), format => run_audio(&project, &meta, &part, &worker, format), }; diff --git a/crates/engine/tests/playback.rs b/crates/engine/tests/playback.rs index 61dec86..81c64f7 100644 --- a/crates/engine/tests/playback.rs +++ b/crates/engine/tests/playback.rs @@ -11,6 +11,7 @@ use std::path::{Path, PathBuf}; use std::thread::sleep; use std::time::{Duration, Instant}; +use engine::export::{ExportSettings, Format}; use engine::project::Lane; use engine::{DecodeSession, Frame, PlaybackSession}; @@ -1170,6 +1171,34 @@ fn an_emptied_timeline_plays_black_saves_loads_and_undoes() { assert!(session.is_eos(), "an empty timeline is played out at once"); session.pause(); + // Exporting nothing is a refusal in words, not a file of no frames -- and + // in the *same* words whichever format asked, because the fence sits in + // `export::start` ahead of the format, not in the mp4 path alone. + for format in [Format::Mp4, Format::Wav, Format::Flac] { + let out = std::env::temp_dir().join(format!("ve_nothing_{}", std::process::id())); + let handle = session.export_to_with( + &out, + &ExportSettings { + format, + ..ExportSettings::default() + }, + ); + let deadline = Instant::now() + Duration::from_secs(10); + let err = loop { + if let Some(result) = handle.result() { + break result.expect_err("an empty timeline cannot be exported"); + } + assert!(Instant::now() < deadline, "{format:?} export never settled"); + sleep(Duration::from_millis(10)); + }; + assert_eq!( + err.to_string(), + "the timeline is empty: there is nothing to export", + "{format:?}" + ); + assert!(!out.exists(), "{format:?} wrote a file anyway"); + } + // It saves and loads back -- still a project, still two lanes, and still // naming the file whose frame rate the timeline counts in. let dir = std::env::temp_dir().join(format!("ve_empty_{}", std::process::id()));