From c92c8c8fa28e91b6efc3a3f4ac1666ca65fa62e5 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sat, 24 Aug 2024 11:26:49 +0200 Subject: [PATCH] VST3: fix deadlock when recalling program changes latency The GUI thread may call set_program() which can triggers the plugin directly calling restartComponent from the same thread. --- libs/ardour/ardour/vst3_plugin.h | 2 ++ libs/ardour/vst3_plugin.cc | 7 ++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/ardour/ardour/vst3_plugin.h b/libs/ardour/ardour/vst3_plugin.h index aaa94f7b9c..feadc6b52b 100644 --- a/libs/ardour/ardour/vst3_plugin.h +++ b/libs/ardour/ardour/vst3_plugin.h @@ -167,6 +167,8 @@ public: Vst::ParamID index_to_id (uint32_t) const; Glib::Threads::Mutex& process_lock () { return _process_lock; } + bool& component_is_synced () { return _restart_component_is_synced; } + enum ParameterChange { BeginGesture, EndGesture, diff --git a/libs/ardour/vst3_plugin.cc b/libs/ardour/vst3_plugin.cc index a7823a7d14..66eb37f5d2 100644 --- a/libs/ardour/vst3_plugin.cc +++ b/libs/ardour/vst3_plugin.cc @@ -1025,9 +1025,10 @@ VST3Plugin::load_preset (PresetRecord r) return false; } - Glib::Threads::Mutex::Lock lx (_plug->process_lock ()); if (tmp[0] == "VST3-P") { + Glib::Threads::Mutex::Lock lx (_plug->process_lock ()); + PBD::Unwinder uw (_plug->component_is_synced (), true); int program = PBD::atoi (tmp[2]); assert (!r.user); if (!_plug->set_program (program, 0)) { @@ -1044,14 +1045,14 @@ VST3Plugin::load_preset (PresetRecord r) std::string const& fn = _preset_uri_map[r.uri]; if (Glib::file_test (fn, Glib::FILE_TEST_EXISTS)) { + Glib::Threads::Mutex::Lock lx (_plug->process_lock ()); + PBD::Unwinder uw (_plug->component_is_synced (), true); RAMStream stream (fn); ok = _plug->load_state (stream); DEBUG_TRACE (DEBUG::VST3Config, string_compose ("VST3Plugin::load_preset: file %1 status %2\n", fn, ok ? "OK" : "error")); } } - lx.release (); - if (ok) { Plugin::load_preset (r); }