From a4851954536bb7706fbf25fcf44242cd5454b5fd Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Fri, 28 Feb 2020 06:35:33 +0100 Subject: Ensure that regions have sources when saving Otherwise this will lead to a corrupt state: ERROR: Session: XMLNode describing a AudioRegion references an unknown source id ERROR: Session: cannot create Region from XML description. Can not load state for region ERROR: Playlist: cannot create region from XML and a track without playlist is created, resulting in a later crash. Eventually SessionPlaylists::load() needs to handle this gracefully, but this should help catch cases causing the actual issue. --- libs/ardour/playlist.cc | 1 + libs/ardour/session_state.cc | 2 ++ 2 files changed, 3 insertions(+) diff --git a/libs/ardour/playlist.cc b/libs/ardour/playlist.cc index 3508eaf0b3..2d89e9f44d 100644 --- a/libs/ardour/playlist.cc +++ b/libs/ardour/playlist.cc @@ -2409,6 +2409,7 @@ Playlist::state (bool full_state) node->set_property ("combine-ops", _combine_ops); for (RegionList::iterator i = regions.begin(); i != regions.end(); ++i) { + assert ((*i)->sources().size() > 0 && (*i)->master_sources().size() > 0); node->add_child_nocopy ((*i)->get_state()); } } diff --git a/libs/ardour/session_state.cc b/libs/ardour/session_state.cc index a7de032375..14da57e95c 100644 --- a/libs/ardour/session_state.cc +++ b/libs/ardour/session_state.cc @@ -1383,6 +1383,8 @@ Session::state (bool save_template, snapshot_t snapshot_type, bool only_used_ass const RegionFactory::RegionMap& region_map (RegionFactory::all_regions()); for (RegionFactory::RegionMap::const_iterator i = region_map.begin(); i != region_map.end(); ++i) { boost::shared_ptr r = i->second; + /* regions must have sources */ + assert (r->sources().size() > 0 && r->master_sources().size() > 0); /* only store regions not attached to playlists */ if (r->playlist() == 0) { if (boost::dynamic_pointer_cast(r)) { -- cgit v1.2.3