mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Don't use STL smart pointers with VST3 interfaces
This would cause double frees since those objects are supposed to clean up after themselves.
This commit is contained in:
@@ -62,4 +62,7 @@ TODO: Explain how we implement `createInstance()`
|
|||||||
- Since everything behind the scenes makes use of these `addRef()` and
|
- Since everything behind the scenes makes use of these `addRef()` and
|
||||||
`release()` reference counting functions, we can't use the standard library's
|
`release()` reference counting functions, we can't use the standard library's
|
||||||
smart pointers when dealing with objects that are shared with the host or with
|
smart pointers when dealing with objects that are shared with the host or with
|
||||||
the Windows VST3 plugin.
|
the Windows VST3 plugin. In `IPtr<T>`'s destructor it will call release, and
|
||||||
|
the objects will clean themselfs up with a `delete this;` when the reference
|
||||||
|
count reaches 0. Combining this with the STL cmart pointers this would result
|
||||||
|
in a double free.
|
||||||
|
|||||||
@@ -86,7 +86,10 @@ Vst3PluginBridge::Vst3PluginBridge()
|
|||||||
Steinberg::IPluginFactory* Vst3PluginBridge::get_plugin_factory() {
|
Steinberg::IPluginFactory* Vst3PluginBridge::get_plugin_factory() {
|
||||||
// Even though we're working with raw pointers here, we should pretend that
|
// Even though we're working with raw pointers here, we should pretend that
|
||||||
// we're `IPtr<Steinberg::IPluginFactory>` and do the reference counting
|
// we're `IPtr<Steinberg::IPluginFactory>` and do the reference counting
|
||||||
// ourselves because you can't always safely pass those around
|
// ourselves because you can't always safely pass those around The VST3
|
||||||
|
// interface can't pass smart pointers around because of binary
|
||||||
|
// compatibility, so we'll have to do the reference counting by hand like in
|
||||||
|
// the implementation in `public.sdk/source/main/pluginfactory.h`.
|
||||||
if (plugin_factory) {
|
if (plugin_factory) {
|
||||||
plugin_factory->addRef();
|
plugin_factory->addRef();
|
||||||
} else {
|
} else {
|
||||||
@@ -94,7 +97,7 @@ Steinberg::IPluginFactory* Vst3PluginBridge::get_plugin_factory() {
|
|||||||
// will request after loading the module. Host callback handlers should
|
// will request after loading the module. Host callback handlers should
|
||||||
// have started before this since the Wine plugin host will request a
|
// have started before this since the Wine plugin host will request a
|
||||||
// copy of the configuration during its initialization.
|
// copy of the configuration during its initialization.
|
||||||
plugin_factory = std::make_unique<YaPluginFactoryPluginImpl>(*this);
|
plugin_factory = Steinberg::owned(new YaPluginFactoryPluginImpl(*this));
|
||||||
sockets.host_vst_control.receive_into(
|
sockets.host_vst_control.receive_into(
|
||||||
WantsPluginFactory{}, *plugin_factory,
|
WantsPluginFactory{}, *plugin_factory,
|
||||||
std::pair<Vst3Logger&, bool>(logger, true));
|
std::pair<Vst3Logger&, bool>(logger, true));
|
||||||
|
|||||||
@@ -80,15 +80,11 @@ class Vst3PluginBridge : PluginBridge<Vst3Sockets<std::jthread>> {
|
|||||||
* Our plugin factory. All information about the plugin and its supported
|
* Our plugin factory. All information about the plugin and its supported
|
||||||
* classes are copied directly from the Windows VST3 plugin's factory on the
|
* classes are copied directly from the Windows VST3 plugin's factory on the
|
||||||
* Wine side, and we'll provide an implementation that can send control
|
* Wine side, and we'll provide an implementation that can send control
|
||||||
* messages to the Wine plugin host. Even though we're passign plain
|
* messages to the Wine plugin host. The VST3 interface only passes raw
|
||||||
* pointers around, we should pretend that they're wrapped in the VST3 SDK's
|
* pointers around and the receiving side should then use `IPtr<T>::adopt()`
|
||||||
* reference counting p pointers so we should do the reference counting
|
* or `owned()` to get back the orignal smart pointer.
|
||||||
* ourselves.
|
|
||||||
*
|
*
|
||||||
* @related get_plugin_factory
|
* @related get_plugin_factory
|
||||||
*
|
|
||||||
* FIXME: We can't use `std::unique_ptr` here because that breaks VST3's
|
|
||||||
* reference counting mechanism.
|
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<YaPluginFactory> plugin_factory;
|
Steinberg::IPtr<YaPluginFactory> plugin_factory;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user