From f9f3f598c4f71dda509c8afbcc3f35da9c3880c7 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 22 Jan 2022 19:26:27 +0100 Subject: [PATCH] Address rare race condition when creating sidechain inputs Do not run the sidechaing processor before the processor was configured. This ensure that Route::configure_processors() has completed and ensure_buffers() was called. Otherwise it may happen Sidechain::run could request a buffer that is n/a (BufferSet::get_available assertion, see also 687149d8d2) --- libs/ardour/plugin_insert.cc | 12 +++++++++--- libs/ardour/sidechain.cc | 3 +-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc index dae5973cc1..6a5cb1a2ca 100644 --- a/libs/ardour/plugin_insert.cc +++ b/libs/ardour/plugin_insert.cc @@ -243,7 +243,14 @@ PluginInsert::set_preset_out (const ChanCount& c) bool PluginInsert::add_sidechain (uint32_t n_audio, uint32_t n_midi) { - // caller must hold process lock + /* Caller must not hold process lock, since add_port() takes the lock. + * + * Since the SC adds a port, an additional buffer may be needed. + * So Route::configure_processors() has to be called to set + * processor_max_streams -> _session.ensure_buffers (). + * SideChain::run () will do nothing before + * _sidechain->configure_io () is called. + */ if (_sidechain) { return false; } @@ -255,8 +262,7 @@ PluginInsert::add_sidechain (uint32_t n_audio, uint32_t n_midi) } else { n << "toBeRenamed" << id().to_s(); } - SideChain *sc = new SideChain (_session, n.str ()); - _sidechain = boost::shared_ptr (sc); + _sidechain.reset (new SideChain (_session, n.str ())); _sidechain->activate (); for (uint32_t n = 0; n < n_audio; ++n) { _sidechain->input()->add_port ("", owner(), DataType::AUDIO); // add a port, don't connect. diff --git a/libs/ardour/sidechain.cc b/libs/ardour/sidechain.cc index a3987ba4e0..33aea30761 100644 --- a/libs/ardour/sidechain.cc +++ b/libs/ardour/sidechain.cc @@ -63,8 +63,7 @@ SideChain::set_state (const XMLNode& node, int version) void SideChain::run (BufferSet& bufs, samplepos_t start_sample, samplepos_t end_sample, double /*speed*/, pframes_t nframes, bool) { - if (_input->n_ports () == ChanCount::ZERO) { - // inplace pass-through + if (_input->n_ports () == ChanCount::ZERO || !_configured) { return; }