Browse Source

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

Signed-off-by: falkTX <falktx@falktx.com>
pull/330/head
falkTX 4 years ago
parent
commit
ef5c2d8a06
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
2 changed files with 29 additions and 4 deletions
  1. +28
    -3
      distrho/src/DistrhoPluginVST3.cpp
  2. +1
    -1
      distrho/src/DistrhoUIVST3.cpp

+ 28
- 3
distrho/src/DistrhoPluginVST3.cpp View File

@@ -23,6 +23,7 @@
#include "travesty/factory.h" #include "travesty/factory.h"


#include <atomic> #include <atomic>
#include <vector>


// TESTING awful idea dont reuse // TESTING awful idea dont reuse
#include "../extra/Thread.hpp" #include "../extra/Thread.hpp"
@@ -1964,6 +1965,11 @@ struct dpf_component : v3_component_cpp {
return V3_NO_INTERFACE; 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 ref = []V3_API(void* self) -> uint32_t
{ {
d_stdout("dpf_component::ref => %p", self); d_stdout("dpf_component::ref => %p", self);
@@ -1979,13 +1985,18 @@ struct dpf_component : v3_component_cpp {
dpf_component* const component = *(dpf_component**)self; dpf_component* const component = *(dpf_component**)self;
DISTRHO_SAFE_ASSERT_RETURN(component != nullptr, 0); 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; *component->self = nullptr;
delete (dpf_component**)self;
return 0; return 0;
}; };
#endif


// ------------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------------
// v3_plugin_base // v3_plugin_base
@@ -2163,6 +2174,8 @@ struct v3_plugin_factory_cpp : v3_funknown {
}; };


struct dpf_factory : v3_plugin_factory_cpp { struct dpf_factory : v3_plugin_factory_cpp {
std::vector<ScopedPointer<dpf_component>*> components;

dpf_factory() dpf_factory()
{ {
static const uint8_t* kSupportedFactories[] = { 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>; ScopedPointer<dpf_component>* const componentptr = new ScopedPointer<dpf_component>;
*componentptr = new dpf_component(componentptr); *componentptr = new dpf_component(componentptr);
*instance = componentptr; *instance = componentptr;
factory->components.push_back(componentptr);
return V3_OK; 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 DISTRHO_PREVENT_HEAP_ALLOCATION
}; };




+ 1
- 1
distrho/src/DistrhoUIVST3.cpp View File

@@ -509,8 +509,8 @@ struct dpf_plugin_view : v3_plugin_view_cpp {
if (const int refcounter = --view->refcounter) if (const int refcounter = --view->refcounter)
return refcounter; return refcounter;


*(dpf_plugin_view**)self = nullptr;
*view->self = nullptr; *view->self = nullptr;
delete (dpf_plugin_view**)self;
return 0; return 0;
}; };




Loading…
Cancel
Save