From ee713dc838be4315eea5ad1e1ef67e477608e720 Mon Sep 17 00:00:00 2001 From: baconpaul Date: Mon, 12 Aug 2024 23:58:26 -0400 Subject: [PATCH] Fix VST3 wrapper in Ardour Ardour creates and derefences an editor instance without ever showing or parenting it (for the reason of finding out if it supports the apu in VST#PI::has_editor). That's a bit odd, but it also meant that _onDestroy was never called, since that was guarded by _created. So add an _onDestroy which knows if ever created and resets just the pointer if not, allowing windows to not crash in Ardour --- src/detail/vst3/plugview.cpp | 13 ++++++++++--- src/detail/vst3/plugview.h | 6 +++--- src/wrapasvst3.cpp | 16 +++++++++------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/src/detail/vst3/plugview.cpp b/src/detail/vst3/plugview.cpp index 2a985d32..0ac59cf4 100644 --- a/src/detail/vst3/plugview.cpp +++ b/src/detail/vst3/plugview.cpp @@ -4,14 +4,14 @@ WrappedView::WrappedView(const clap_plugin_t* plugin, const clap_plugin_gui_t* gui, std::function onReleaseAdditionalReferences, - std::function onDestroy, std::function onRunLoopAvailable) + std::function onDestroy, std::function onRunLoopAvailable) : IPlugView() , FObject() , _plugin(plugin) , _extgui(gui) , _onReleaseAdditionalReferences(onReleaseAdditionalReferences) - , _onDestroy(onDestroy) , _onRunLoopAvailable(onRunLoopAvailable) + , _onDestroy(onDestroy) { } @@ -49,11 +49,18 @@ void WrappedView::drop_ui() _attached = false; if (_onDestroy) { - _onDestroy(); + _onDestroy(true); } _extgui->destroy(_plugin); _created = false; } + else + { + if (_onDestroy) + { + _onDestroy(false); + } + } } void WrappedView::releaseAdditionalReferences() diff --git a/src/detail/vst3/plugview.h b/src/detail/vst3/plugview.h index f9d1e989..2e806838 100644 --- a/src/detail/vst3/plugview.h +++ b/src/detail/vst3/plugview.h @@ -19,7 +19,7 @@ class WrappedView : public Steinberg::IPlugView, public Steinberg::FObject { public: WrappedView(const clap_plugin_t* plugin, const clap_plugin_gui_t* gui, - std::function onReleaseAdditionalReferences, std::function onDestroy, + std::function onReleaseAdditionalReferences, std::function onDestroy, std::function onRunLoopAvailable); ~WrappedView(); @@ -94,8 +94,8 @@ class WrappedView : public Steinberg::IPlugView, public Steinberg::FObject void releaseAdditionalReferences(); const clap_plugin_t* _plugin = nullptr; const clap_plugin_gui_t* _extgui = nullptr; - std::function _onReleaseAdditionalReferences = nullptr, _onDestroy = nullptr, - _onRunLoopAvailable = nullptr; + std::function _onReleaseAdditionalReferences = nullptr, _onRunLoopAvailable = nullptr; + std::function _onDestroy = nullptr; clap_window_t _window = {nullptr, {nullptr}}; IPlugFrame* _plugFrame = nullptr; ViewRect _rect = {0, 0, 0, 0}; diff --git a/src/wrapasvst3.cpp b/src/wrapasvst3.cpp index 9bf4dbd0..be1c0fe7 100644 --- a/src/wrapasvst3.cpp +++ b/src/wrapasvst3.cpp @@ -60,7 +60,6 @@ tresult PLUGIN_API ClapAsVst3::initialize(FUnknown* context) tresult PLUGIN_API ClapAsVst3::terminate() { - clearContextMenu(); vst3HostApplication.reset(); if (_plugin) @@ -260,16 +259,19 @@ IPlugView* PLUGIN_API ClapAsVst3::createView(FIDString /*name*/) { _wrappedview = new WrappedView( _plugin->_plugin, _plugin->_ext._gui, [this]() { clearContextMenu(); }, - [this]() + [this](bool everCreated) { + if (everCreated) + { #if LIN - // the host calls the destructor, the wrapper just removes its pointer - detachTimers(_wrappedview->getRunLoop()); - detachPosixFD(_wrappedview->getRunLoop()); - _iRunLoop = nullptr; + // the host calls the destructor, the wrapper just removes its pointer + detachTimers(_wrappedview->getRunLoop()); + detachPosixFD(_wrappedview->getRunLoop()); + _iRunLoop = nullptr; #endif - clearContextMenu(); + clearContextMenu(); + } this->_wrappedview = nullptr; }, [this]()