From 9e9fd201b526afac2cc52c12c1d670f5cf49e1eb Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 13 Mar 2024 03:56:01 +0100 Subject: [PATCH] Prevent crashes when trying to add/remove IOPlug ports IOPlugins pinout is not [yet] configurable. Trying to add ports resuled in a segfault since the BufferSet was not resized (nor the plugin reconfigured) --- libs/ardour/ardour/io_plug.h | 1 + libs/ardour/io_plug.cc | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/libs/ardour/ardour/io_plug.h b/libs/ardour/ardour/io_plug.h index a4a2da63dc..22a05331dc 100644 --- a/libs/ardour/ardour/io_plug.h +++ b/libs/ardour/ardour/io_plug.h @@ -161,6 +161,7 @@ private: BufferSet _bufs; std::shared_ptr _input; std::shared_ptr _output; + bool _configuring_io; PortManager::AudioInputPorts _audio_input_ports; PortManager::MIDIInputPorts _midi_input_ports; diff --git a/libs/ardour/io_plug.cc b/libs/ardour/io_plug.cc index bfa7957a19..ed7c3ca37b 100644 --- a/libs/ardour/io_plug.cc +++ b/libs/ardour/io_plug.cc @@ -18,6 +18,7 @@ #include #include "pbd/types_convert.h" +#include "pbd/unwind.h" #include "pbd/xml++.h" #include "temporal/tempo.h" @@ -46,6 +47,7 @@ IOPlug::IOPlug (Session& s, std::shared_ptr p, bool pre) , _plugin (p) , _pre (pre) , _plugin_signal_latency (0) + , _configuring_io (false) , _window_proxy (0) { _stat_reset.store (0); @@ -57,6 +59,12 @@ IOPlug::IOPlug (Session& s, std::shared_ptr p, bool pre) } _input.reset (new IO (_session, io_name (), IO::Input)); _output.reset (new IO (_session, io_name (), IO::Output)); + + /* do not allow to add/remove ports (for now). + * when adding ports _buf will needs to be resized. + */ + _input->PortCountChanging.connect_same_thread (*this, [this](ChanCount) { return !_configuring_io; }); + _output->PortCountChanging.connect_same_thread (*this, [this](ChanCount) { return !_configuring_io; }); } IOPlug::~IOPlug () @@ -380,6 +388,8 @@ IOPlug::ui_elements () const bool IOPlug::ensure_io () { + PBD::Unwinder uw (_configuring_io, true); + /* must be called with process-lock held */ if (_input->ensure_io (_n_in, false, this) != 0) { return false;