DPF

DISTRHO Plugin Framework
Log | Files | Refs | Submodules | README | LICENSE

commit ef5c2d8a067c727c8186105f12f74b93880cc9b5
parent db465f69b2fbe30788469b29ee9425f64ada280a
Author: falkTX <falktx@falktx.com>
Date:   Sat, 25 Sep 2021 12:24:33 +0100

VST3: Fix UI object lifetime, add temp workaround for component

Signed-off-by: falkTX <falktx@falktx.com>

Diffstat:
Mdistrho/src/DistrhoPluginVST3.cpp | 31++++++++++++++++++++++++++++---
Mdistrho/src/DistrhoUIVST3.cpp | 2+-
2 files changed, 29 insertions(+), 4 deletions(-)

diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp @@ -23,6 +23,7 @@ #include "travesty/factory.h" #include <atomic> +#include <vector> // TESTING awful idea dont reuse #include "../extra/Thread.hpp" @@ -1964,6 +1965,11 @@ struct dpf_component : v3_component_cpp { return V3_NO_INTERFACE; }; +#if 1 + // TODO fix this up later + ref = []V3_API(void*) -> uint32_t { return 1; }; + unref = []V3_API(void*) -> uint32_t { return 0; }; +#else ref = []V3_API(void* self) -> uint32_t { d_stdout("dpf_component::ref => %p", self); @@ -1979,13 +1985,18 @@ struct dpf_component : v3_component_cpp { dpf_component* const component = *(dpf_component**)self; DISTRHO_SAFE_ASSERT_RETURN(component != nullptr, 0); - if (const int refcounter = --component->refcounter) - return refcounter; + if (const int refcount = --component->refcounter) + { + d_stdout("dpf_component::unref => %p | refcount %i", self, refcount); + return refcount; + } - *(dpf_component**)self = nullptr; + d_stdout("dpf_component::unref => %p | refcount is zero, deleting everything now!", self); *component->self = nullptr; + delete (dpf_component**)self; return 0; }; +#endif // ------------------------------------------------------------------------------------------------------------ // v3_plugin_base @@ -2163,6 +2174,8 @@ struct v3_plugin_factory_cpp : v3_funknown { }; struct dpf_factory : v3_plugin_factory_cpp { + std::vector<ScopedPointer<dpf_component>*> components; + dpf_factory() { static const uint8_t* kSupportedFactories[] = { @@ -2252,6 +2265,7 @@ struct dpf_factory : v3_plugin_factory_cpp { ScopedPointer<dpf_component>* const componentptr = new ScopedPointer<dpf_component>; *componentptr = new dpf_component(componentptr); *instance = componentptr; + factory->components.push_back(componentptr); return V3_OK; }; @@ -2304,6 +2318,17 @@ struct dpf_factory : v3_plugin_factory_cpp { }; } + ~dpf_factory() + { + d_stdout("dpf_factory deleting"); + + for (ScopedPointer<dpf_component>* componentptr : components) + { + *componentptr = nullptr; + delete componentptr; + } + } + DISTRHO_PREVENT_HEAP_ALLOCATION }; diff --git a/distrho/src/DistrhoUIVST3.cpp b/distrho/src/DistrhoUIVST3.cpp @@ -509,8 +509,8 @@ struct dpf_plugin_view : v3_plugin_view_cpp { if (const int refcounter = --view->refcounter) return refcounter; - *(dpf_plugin_view**)self = nullptr; *view->self = nullptr; + delete (dpf_plugin_view**)self; return 0; };