mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-10 04:30:12 +02:00
Work around a memory corruption issue on unload
I'm really not sure what is happening here, and it might just be a winelib thing.
This commit is contained in:
@@ -67,7 +67,10 @@ Vst2Bridge& get_bridge_instance(const AEffect* plugin) {
|
|||||||
|
|
||||||
Vst2Bridge::Vst2Bridge(std::string plugin_dll_path,
|
Vst2Bridge::Vst2Bridge(std::string plugin_dll_path,
|
||||||
std::string socket_endpoint_path)
|
std::string socket_endpoint_path)
|
||||||
: plugin_handle(LoadLibrary(plugin_dll_path.c_str()), FreeLibrary),
|
// See `plugin_handle`s docstring for information on why we're leaking
|
||||||
|
// memory here
|
||||||
|
// : plugin_handle(LoadLibrary(plugin_dll_path.c_str()), FreeLibrary),
|
||||||
|
: plugin_handle(LoadLibrary(plugin_dll_path.c_str())),
|
||||||
io_context(),
|
io_context(),
|
||||||
socket_endpoint(socket_endpoint_path),
|
socket_endpoint(socket_endpoint_path),
|
||||||
host_vst_dispatch(io_context),
|
host_vst_dispatch(io_context),
|
||||||
@@ -85,9 +88,8 @@ Vst2Bridge::Vst2Bridge(std::string plugin_dll_path,
|
|||||||
// there are some older deprecated names that legacy plugins may still use
|
// there are some older deprecated names that legacy plugins may still use
|
||||||
VstEntryPoint vst_entry_point = nullptr;
|
VstEntryPoint vst_entry_point = nullptr;
|
||||||
for (auto name : {"VSTPluginMain", "main_plugin", "main"}) {
|
for (auto name : {"VSTPluginMain", "main_plugin", "main"}) {
|
||||||
vst_entry_point =
|
vst_entry_point = reinterpret_cast<VstEntryPoint>(
|
||||||
reinterpret_cast<VstEntryPoint>(reinterpret_cast<size_t>(
|
reinterpret_cast<size_t>(GetProcAddress(plugin_handle, name)));
|
||||||
GetProcAddress(plugin_handle.get(), name)));
|
|
||||||
|
|
||||||
if (vst_entry_point != nullptr) {
|
if (vst_entry_point != nullptr) {
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -165,10 +165,19 @@ class Vst2Bridge {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* The shared library handle of the VST plugin. I sadly could not get
|
* The shared library handle of the VST plugin. I sadly could not get
|
||||||
* Boost.DLL to work here, so we'll just load the VST plugisn by hand.
|
* Boost.DLL to work here, so we'll just load the VST plugins by hand.
|
||||||
|
*
|
||||||
|
* FIXME: I don't know why, but `FreeLibrary()` seems to corrupt memory.
|
||||||
|
* This leads to a lot of weird behavior, such as plugins crashing as
|
||||||
|
* soon as other plugins get loaded or calls to `LoadLibrary()`
|
||||||
|
* returning null pointers while they would otherwise load fine
|
||||||
|
* without the prior call to `FreeLibrary`. We are leaking memory
|
||||||
|
* here until this is fixed, but it should not be a huge issue since
|
||||||
|
* this leak only exists for plugin groups.
|
||||||
*/
|
*/
|
||||||
std::unique_ptr<std::remove_pointer_t<HMODULE>, decltype(&FreeLibrary)>
|
// std::unique_ptr<std::remove_pointer_t<HMODULE>, decltype(&FreeLibrary)>
|
||||||
plugin_handle;
|
// plugin_handle;
|
||||||
|
HMODULE plugin_handle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The loaded plugin's `AEffect` struct, obtained using the above library
|
* The loaded plugin's `AEffect` struct, obtained using the above library
|
||||||
|
|||||||
Reference in New Issue
Block a user