SDK 3.7.5 Again AUv2 Crash on close

After 2 days of trying to get a working AUv3 version of the AGain project, I decided it would be prudent to try my luck with AUv2 instead.

Unfortunately even the AUv2 version is crashing on plugin removal. Any ideas?

Process:               Logic Pro X [2240]
Path:                  /Applications/Logic Pro X.app/Contents/MacOS/Logic Pro X
Identifier:            com.apple.logic10
Version:               10.6.3 (5458)
Build Info:            MALogic-5458000000000000~3 (10U159)
App Item ID:           634148309
App External ID:       841990097
Code Type:             X86-64 (Native)
Parent Process:        ??? [1]
Responsible:           Logic Pro X [2240]
User ID:               501

Date/Time:             2022-06-15 11:40:35.712 +0800
OS Version:            Mac OS X 10.15.7 (19H1519)
Report Version:        12
Bridge OS Version:     6.4 (19P4243)
Anonymous UUID:        B8DA52AB-9339-56BF-560C-8A553D8C34B7


Time Awake Since Boot: 910 seconds

System Integrity Protection: enabled

Crashed Thread:        0  Dispatch queue: com.apple.main-thread

Exception Type:        EXC_CRASH (SIGABRT)
Exception Codes:       0x0000000000000000, 0x0000000000000000
Exception Note:        EXC_CORPSE_NOTIFY

Termination Reason:    Namespace OBJC, Code 0x1

Application Specific Information:
Dublin | 6b34edbe1e2428234532a9a90f0dda622834cd344de3e01f645f6cf5be04bce1 | c226c3f729b55e358699a7f7b18f27a9803c1159 | 2021-07-07_15:09:24
 
Attempt to use unknown class 0x600000475290.

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        	0x00007fff705e4ad6 __abort_with_payload + 10
1   libsystem_kernel.dylib        	0x00007fff705e63df abort_with_payload_wrapper_internal + 80
2   libsystem_kernel.dylib        	0x00007fff705e638f abort_with_reason + 19
3   libobjc.A.dylib               	0x00007fff6f2ec820 _objc_fatalv(unsigned long long, unsigned long long, char const*, __va_list_tag*) + 114
4   libobjc.A.dylib               	0x00007fff6f2ec7ae _objc_fatal(char const*, ...) + 135
5   libobjc.A.dylib               	0x00007fff6f2cfc37 lookUpImpOrForward + 802
6   libobjc.A.dylib               	0x00007fff6f2cf399 _objc_msgSend_uncached + 73
7   com.apple.AppKit              	0x00007fff3363dc47 _detach2 + 34
8   libobjc.A.dylib               	0x00007fff6f2ec054 AutoreleasePoolPage::releaseUntil(objc_object**) + 134
9   libobjc.A.dylib               	0x00007fff6f2d0dba objc_autoreleasePoolPop + 175
10  com.apple.CoreFoundation      	0x00007fff36333315 _CFAutoreleasePoolPop + 22
11  com.apple.Foundation          	0x00007fff389e503e -[NSAutoreleasePool drain] + 126
12  com.apple.AppKit              	0x00007fff335d8c12 -[NSApplication run] + 758
13  com.apple.AppKit              	0x00007fff335aa996 NSApplicationMain + 777
14  com.apple.logic10             	0x000000010663786d 0x105a88000 + 12253293
15  libdyld.dylib                 	0x00007fff70483cc9 start + 1

Some more details on this.

  • If the plugin is off or the the UI is closed, then there is no crash on plugin removal.
  • If more than one instance of the plugin is loaded, and they are removed such that the first instance is removed last, there is no crash.

I’m working macOS 10.15.7 and Xcode 12.4. Looking through the wrapper code, it looks like the code below is the culprit. MAC_OS_X_VERSION_10_11 is defined on my system. If I remove the workaround everything is fine.

            #if defined(MAC_OS_X_VERSION_10_11)
			// workaround, because CFBundleCreate returns refcount == 2.
			if (CFBundleIsExecutableLoaded ((CFBundleRef)instance))
			{
				CFBundleUnloadExecutable ((CFBundleRef)instance);
				CFRelease ((CFBundleRef)instance);
			}
            #else
			CFRelease ((CFBundleRef)instance);
            #endif