From 6742a0961c928e0d444ef0972a6a68bb8b9e40f6 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Wed, 5 Aug 2020 22:39:06 +0200 Subject: [PATCH] Ask LuaProc to drop references This fixes a circular shared_ptr<> reference that prevents plugin destruction. LuaProc may hold references to Route that contains the plugin or the PluginInsert of the LuaPlugin. These are only dropped when the interpreter collects garbage. Previously this happened in the d'tor or LuaProc, but while the Plugin has a reference to the Insert, the Insert is not deleted and the d'tor is never called. --- libs/ardour/ardour/luaproc.h | 2 ++ libs/ardour/ardour/plugin.h | 2 ++ libs/ardour/ardour/plugin_insert.h | 2 ++ libs/ardour/luaproc.cc | 8 +++++++- libs/ardour/plugin_insert.cc | 9 +++++++++ 5 files changed, 22 insertions(+), 1 deletion(-) diff --git a/libs/ardour/ardour/luaproc.h b/libs/ardour/ardour/luaproc.h index fa8a826778..d2acc9600d 100644 --- a/libs/ardour/ardour/luaproc.h +++ b/libs/ardour/ardour/luaproc.h @@ -78,6 +78,8 @@ public: PluginOutputConfiguration possible_output () const { return _output_configs; } + void drop_references (); + std::set automatable() const; void activate () { } diff --git a/libs/ardour/ardour/plugin.h b/libs/ardour/ardour/plugin.h index a062cc8858..5653a8bc0d 100644 --- a/libs/ardour/ardour/plugin.h +++ b/libs/ardour/ardour/plugin.h @@ -106,6 +106,8 @@ public: activate (); } + virtual void drop_references () {} + virtual std::set automatable () const = 0; virtual std::string describe_parameter (Evoral::Parameter) = 0; virtual std::string state_node_name () const = 0; diff --git a/libs/ardour/ardour/plugin_insert.h b/libs/ardour/ardour/plugin_insert.h index f627184a05..200edf0d4c 100644 --- a/libs/ardour/ardour/plugin_insert.h +++ b/libs/ardour/ardour/plugin_insert.h @@ -61,6 +61,8 @@ public: PluginInsert (Session&, boost::shared_ptr = boost::shared_ptr()); ~PluginInsert (); + void drop_references (); + static const std::string port_automation_node_name; int set_state(const XMLNode&, int version); diff --git a/libs/ardour/luaproc.cc b/libs/ardour/luaproc.cc index a1bbd1c5c9..ba388a2569 100644 --- a/libs/ardour/luaproc.cc +++ b/libs/ardour/luaproc.cc @@ -130,7 +130,7 @@ LuaProc::~LuaProc () { _stats_max[1] * (float)_stats_cnt / _stats_avg[1]); } #endif - lua.do_command ("collectgarbage();"); + lua.collect_garbage (); delete (_lua_dsp); delete (_lua_latency); delete [] _control_data; @@ -182,6 +182,12 @@ LuaProc::init () lua.do_command ("function ardour () end"); } +void +LuaProc::drop_references () +{ + lua.collect_garbage (); +} + boost::weak_ptr LuaProc::route () const { diff --git a/libs/ardour/plugin_insert.cc b/libs/ardour/plugin_insert.cc index 47c5faf3dc..a654f2b625 100644 --- a/libs/ardour/plugin_insert.cc +++ b/libs/ardour/plugin_insert.cc @@ -110,6 +110,15 @@ PluginInsert::~PluginInsert () } } +void +PluginInsert::drop_references () +{ + for (Plugins::iterator i = _plugins.begin(); i != _plugins.end(); ++i) { + (*i)->drop_references (); + } + Processor::drop_references (); +} + void PluginInsert::set_strict_io (bool b) {