mirror of
https://github.com/Ardour/ardour.git
synced 2025-12-16 19:56:31 +01:00
Fix crashes when unloading mac VST2 plugins
CFBundleRef is reference counted, so we need to retain a reference. Previously it went out of scope at the end of mac_vst_load().
This commit is contained in:
parent
5e54425a35
commit
b01fe8b0e4
2 changed files with 20 additions and 15 deletions
|
|
@ -25,6 +25,10 @@
|
||||||
#include "ardour/libardour_visibility.h"
|
#include "ardour/libardour_visibility.h"
|
||||||
#include "ardour/vestige/vestige.h"
|
#include "ardour/vestige/vestige.h"
|
||||||
|
|
||||||
|
#ifdef MACVST_SUPPORT
|
||||||
|
#include <Carbon/Carbon.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
struct LIBARDOUR_API _VSTKey
|
struct LIBARDOUR_API _VSTKey
|
||||||
{
|
{
|
||||||
/** virtual-key code, or 0 if this _VSTFXKey is a `character' key */
|
/** virtual-key code, or 0 if this _VSTFXKey is a `character' key */
|
||||||
|
|
@ -62,16 +66,17 @@ typedef AEffect * (* main_entry_t) (audioMasterCallback);
|
||||||
|
|
||||||
struct LIBARDOUR_API _VSTHandle
|
struct LIBARDOUR_API _VSTHandle
|
||||||
{
|
{
|
||||||
void* dll;
|
#ifdef MACVST_SUPPORT
|
||||||
|
CFBundleRef bundleRef;
|
||||||
|
CFBundleRefNum res_file_id;
|
||||||
|
#else
|
||||||
|
void* dll;
|
||||||
|
#endif
|
||||||
|
|
||||||
char* name;
|
char* name;
|
||||||
char* path;
|
char* path;
|
||||||
|
|
||||||
main_entry_t main_entry;
|
main_entry_t main_entry;
|
||||||
|
|
||||||
int plugincnt;
|
int plugincnt;
|
||||||
#ifdef MACVST_SUPPORT
|
|
||||||
int32_t res_file_id;
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct _VSTHandle VSTHandle;
|
typedef struct _VSTHandle VSTHandle;
|
||||||
|
|
|
||||||
|
|
@ -97,33 +97,33 @@ mac_vst_load (const char *path)
|
||||||
fhandle = mac_vst_handle_new ();
|
fhandle = mac_vst_handle_new ();
|
||||||
|
|
||||||
fhandle->dll = NULL;
|
fhandle->dll = NULL;
|
||||||
|
fhandle->bundleRef = 0;
|
||||||
|
|
||||||
CFURLRef url;
|
CFURLRef url;
|
||||||
if (!(url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*)path, (CFIndex) strlen (path), true))) {
|
if (!(url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*)path, (CFIndex) strlen (path), true))) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
|
fhandle->bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
|
||||||
CFRelease (url);
|
CFRelease (url);
|
||||||
|
|
||||||
if (bundleRef == 0) {
|
if (fhandle->bundleRef == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CFBundleLoadExecutable (bundleRef)) {
|
if (!CFBundleLoadExecutable (fhandle->bundleRef)) {
|
||||||
CFRelease (bundleRef);
|
CFRelease (fhandle->bundleRef);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fhandle->name = strdup (path);
|
fhandle->name = strdup (path);
|
||||||
fhandle->dll = (void*) &bundleRef;
|
|
||||||
|
|
||||||
fhandle->main_entry = (main_entry_t)
|
fhandle->main_entry = (main_entry_t)
|
||||||
CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
|
CFBundleGetFunctionPointerForName (fhandle->bundleRef, CFSTR("main_macho"));
|
||||||
|
|
||||||
if (!fhandle->main_entry) {
|
if (!fhandle->main_entry) {
|
||||||
fhandle->main_entry = (main_entry_t)
|
fhandle->main_entry = (main_entry_t)
|
||||||
CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
|
CFBundleGetFunctionPointerForName (fhandle->bundleRef, CFSTR("VSTPluginMain"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fhandle->main_entry == 0) {
|
if (fhandle->main_entry == 0) {
|
||||||
|
|
@ -131,7 +131,7 @@ mac_vst_load (const char *path)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
fhandle->res_file_id = CFBundleOpenBundleResourceMap (bundleRef);
|
fhandle->res_file_id = CFBundleOpenBundleResourceMap (fhandle->bundleRef);
|
||||||
|
|
||||||
/*return the handle of the plugin*/
|
/*return the handle of the plugin*/
|
||||||
return fhandle;
|
return fhandle;
|
||||||
|
|
@ -150,7 +150,7 @@ mac_vst_unload (VSTHandle* fhandle)
|
||||||
|
|
||||||
/*Valid plugin loaded?*/
|
/*Valid plugin loaded?*/
|
||||||
|
|
||||||
if (fhandle->dll)
|
if (fhandle->bundleRef)
|
||||||
{
|
{
|
||||||
CFBundleRef* bundleRefPtr = (CFBundleRef*) fhandle->dll;
|
CFBundleRef* bundleRefPtr = (CFBundleRef*) fhandle->dll;
|
||||||
CFBundleCloseBundleResourceMap (*bundleRefPtr, (CFBundleRefNum)fhandle->res_file_id);
|
CFBundleCloseBundleResourceMap (*bundleRefPtr, (CFBundleRefNum)fhandle->res_file_id);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue