diff --git a/distrho/src/DistrhoPluginVST3.cpp b/distrho/src/DistrhoPluginVST3.cpp index 640dcb65..fc934c68 100644 --- a/distrho/src/DistrhoPluginVST3.cpp +++ b/distrho/src/DistrhoPluginVST3.cpp @@ -23,6 +23,7 @@ #include "travesty/factory.h" #include +#include // 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*> components; + dpf_factory() { static const uint8_t* kSupportedFactories[] = { @@ -2252,6 +2265,7 @@ struct dpf_factory : v3_plugin_factory_cpp { ScopedPointer* const componentptr = new ScopedPointer; *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* componentptr : components) + { + *componentptr = nullptr; + delete componentptr; + } + } + DISTRHO_PREVENT_HEAP_ALLOCATION }; diff --git a/distrho/src/DistrhoUIVST3.cpp b/distrho/src/DistrhoUIVST3.cpp index f58b2156..5a42a5e2 100644 --- 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; };