Fix save crash on zero/sparse-audio projects (phantom pool placeholder)

`AudioPool::load_from_serialized` sizes the slot Vec by pool_index and fills gaps
with empty `AudioFile::new(PathBuf::new(), …)` placeholders. Two bugs let a
placeholder reach the next save and abort it with "Is a directory":

- Off-by-one: `entries.max().unwrap_or(0) + 1` made an *empty* pool length 1, so a
  project with no audio still got one placeholder. Size by `max(pool_index + 1)`
  → empty entries yield length 0.
- `serialize()` emitted placeholder slots: an empty path round-trips to
  `relative_path = Some("")`, which `save_beam` resolves to the project directory
  (`join("")`) and tries to read as media. Skip empty-path / no-packed-media slots.
- Defense in `save_beam`: gate referenced-media packing on `full.is_file()` (not
  `exists()`), so any blank/dir path falls through to embedded data instead of
  reading a directory.

Pre-existing; surfaced by a save → reload → save cycle on a raster-only project.
This commit is contained in:
Skyler Lehmkuhl
2026-06-20 18:46:19 -04:00
parent 39dc402ba3
commit d001ca1083
2 changed files with 22 additions and 6 deletions
@@ -324,7 +324,11 @@ pub fn save_beam(
} else {
project_dir.join(rel)
};
if full.exists() {
// Require an actual file: an empty/blank `relative_path` resolves to the
// project directory itself (`join("")` == dir), which `exists()` accepts
// but can't be read as media. `is_file()` skips dirs + missing paths, so
// such an entry correctly falls through to embedded data below.
if full.is_file() {
let size = std::fs::metadata(&full).map(|m| m.len()).unwrap_or(0);
let codec = full
.extension()