From 62f376d952f24fe0f9d6c0fb2a65bf446fd048a4 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Mon, 14 Dec 2020 22:49:20 +0100 Subject: [PATCH] Allow the module to be properly unloaded Terminating the host process will cause all sockets to be closed so we can join the threads. --- src/plugin/bridges/vst2.cpp | 2 ++ src/plugin/bridges/vst3.cpp | 6 ++++++ src/plugin/bridges/vst3.h | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/src/plugin/bridges/vst2.cpp b/src/plugin/bridges/vst2.cpp index 15a9bca8..54f394f0 100644 --- a/src/plugin/bridges/vst2.cpp +++ b/src/plugin/bridges/vst2.cpp @@ -396,6 +396,8 @@ intptr_t Vst2PluginBridge::dispatch(AEffect* /*plugin*/, // been caused by pipes and sockets being closed. io_context.stop(); + // TODO: For consistency with the VST3 version, move the above to + // the destructor delete this; return return_value; diff --git a/src/plugin/bridges/vst3.cpp b/src/plugin/bridges/vst3.cpp index 7c1073a3..c8e45e95 100644 --- a/src/plugin/bridges/vst3.cpp +++ b/src/plugin/bridges/vst3.cpp @@ -83,6 +83,12 @@ Vst3PluginBridge::Vst3PluginBridge() }); } +Vst3PluginBridge::~Vst3PluginBridge() { + // Drop all work make sure all sockets are closed + plugin_host->terminate(); + io_context.stop(); +} + Steinberg::IPluginFactory* Vst3PluginBridge::get_plugin_factory() { // Even though we're working with raw pointers here, we should pretend that // we're `IPtr` and do the reference counting diff --git a/src/plugin/bridges/vst3.h b/src/plugin/bridges/vst3.h index 249bfc9e..86e54404 100644 --- a/src/plugin/bridges/vst3.h +++ b/src/plugin/bridges/vst3.h @@ -55,6 +55,12 @@ class Vst3PluginBridge : PluginBridge> { */ Vst3PluginBridge(); + /** + * Terminate the Wine plugin host process and drop all work when the module + * gets unloaded. + */ + ~Vst3PluginBridge(); + /** * When the host loads the module it will call `GetPluginFactory()` which * will in turn call this function. The idea is that we return an