From 4448b3a2a99a520fdc7fc06c4a72ea2a84b863b5 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 20 Nov 2022 15:01:08 +0100 Subject: [PATCH] Prevent crash when running unconfigured meter processor If Route::configure_processors fails at session start, meters are not configured (#9106), leading to a crash when ::run() is called (insufficient peak/max/midi buffers). --- libs/ardour/ardour/meter.h | 1 + libs/ardour/meter.cc | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/libs/ardour/ardour/meter.h b/libs/ardour/ardour/meter.h index b6fb104a34..036c206764 100644 --- a/libs/ardour/ardour/meter.h +++ b/libs/ardour/ardour/meter.h @@ -99,6 +99,7 @@ private: * as it can be altered outside a \ref configure_io by \ref reflect_inputs . */ ChanCount current_meters; + ChanCount _max_n_meters; GATOMIC_QUAL gint _reset_dpm; GATOMIC_QUAL gint _reset_max; diff --git a/libs/ardour/meter.cc b/libs/ardour/meter.cc index 435d00d8cf..763cd74d09 100644 --- a/libs/ardour/meter.cc +++ b/libs/ardour/meter.cc @@ -269,6 +269,23 @@ PeakMeter::configure_io (ChanCount in, ChanCount out) void PeakMeter::reflect_inputs (const ChanCount& in) { + if (!_configured || in > _max_n_meters) { + /* meter has to be configured at least once, and + * Route has to call ::set_max_channels after successful + * configure_processors. + */ + return; + } + + /* In theory this cannot happen. After an initial successful + * configuration, Route::configure_processors_unlocked will revert + * to a prior config in case of an error. + */ + assert (in <= _max_n_meters); + if (in > _max_n_meters) { + return; + } + reset (); current_meters = in; reset_max (); @@ -283,6 +300,8 @@ PeakMeter::emit_configuration_changed () void PeakMeter::set_max_channels (const ChanCount& chn) { + _max_n_meters = chn; + uint32_t const limit = chn.n_total (); const size_t n_audio = chn.n_audio ();