From e34359b9210e5fe78d45ad1845efe95d72e0b9c0 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 20 May 2024 18:56:48 +0200 Subject: [PATCH] VST3: skip context info callbacks during session load This fixes a crash when SSL's channelstrip calls set-selection early on during session load, during Session::load_routes. Session::add_routes_inner calls calls ARDOUR::GUIIdle() which can trigger a SSL Native Channel Strip 2" VST3 to call VST3PI::setContextInfoValue, which in turn emits a CoreSelection::send_selection_change before the session is fully loaded. This also handles various edge cases where a given AC may not [yet] exist. --- libs/ardour/vst3_plugin.cc | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/libs/ardour/vst3_plugin.cc b/libs/ardour/vst3_plugin.cc index d9f6227fa9..313751f659 100644 --- a/libs/ardour/vst3_plugin.cc +++ b/libs/ardour/vst3_plugin.cc @@ -2969,14 +2969,21 @@ VST3PI::getContextInfoValue (double& value, FIDString id) tresult VST3PI::setContextInfoValue (FIDString id, double value) { - if (!_owner) { + Stripable* s = dynamic_cast (_owner); + if (!s) { DEBUG_TRACE (DEBUG::VST3Callbacks, "VST3PI::setContextInfoValue: not initialized"); return kNotInitialized; } DEBUG_TRACE (DEBUG::VST3Callbacks, string_compose ("VST3PI::setContextInfoValue %1 to %2\n", id, value)); + if (s->session ().loading () || s->session ().deletion_in_progress ()) { + return kResultOk; + } if (0 == strcmp (id, ContextInfo::kVolume)) { std::shared_ptr ac = lookup_ac (_owner, id); - ac->set_value (value, Controllable::NoGroup); + assert (ac); + if (ac) { + ac->set_value (value, Controllable::NoGroup); + } } else if (0 == strcmp (id, ContextInfo::kPan)) { std::shared_ptr ac = lookup_ac (_owner, id); if (ac) { @@ -3005,6 +3012,9 @@ VST3PI::setContextInfoValue (FIDString id, int32 value) return kNotInitialized; } DEBUG_TRACE (DEBUG::VST3Callbacks, string_compose ("VST3PI::setContextInfoValue %1 to %2\n", id, value)); + if (s->session ().loading () || s->session ().deletion_in_progress ()) { + return kResultOk; + } if (0 == strcmp (id, ContextInfo::kColor)) { #if BYTEORDER == kBigEndian SWAP_32 (value) // ABGR32 -> RGBA32 @@ -3022,10 +3032,11 @@ VST3PI::setContextInfoValue (FIDString id, int32 value) } } else if (0 == strcmp (id, ContextInfo::kMultiSelect)) { _add_to_selection = value != 0; - } else if (0 == strcmp (id, ContextInfo::kMute)) { - s->session ().set_control (lookup_ac (_owner, id), value != 0 ? 1 : 0, Controllable::NoGroup); - } else if (0 == strcmp (id, ContextInfo::kSolo)) { - s->session ().set_control (lookup_ac (_owner, id), value != 0 ? 1 : 0, Controllable::NoGroup); + } else if (0 == strcmp (id, ContextInfo::kMute) || 0 == strcmp (id, ContextInfo::kSolo)) { + std::shared_ptr ac = lookup_ac (_owner, id); + if (ac) { + s->session ().set_control (ac, value != 0 ? 1 : 0, Controllable::NoGroup); + } } else { DEBUG_TRACE (DEBUG::VST3Callbacks, "VST3PI::setContextInfoValue: unsupported ID\n"); return kNotImplemented;