Hello,
I was able to isolate an issue affecting AUv3 hosts, where multiple intanciation of AUv3 plug-ins would randomly lead to unexpected behavior / inconsistency in the host. I tried both on iOS 9.3.5 and iOS 10.3.2, both showing the same results.
This happens when loading back a project containing multiple instances of the same plugin. In my case, this is not done on the main thread but on a worker thread which take care of various "heavy" tasks. I use [AUAudioUnit instantiateWithComponentDescription: options: completionHandler:] to instanciate clients. When the completion handler gets called, I will setup my structure, and call allocateRenderResourcesAndReturnError, restore state, and cache the various blocks for later use.
Some AUv3 plugins will reload just fine, but some will randomly fail. I could observe multiple reasons for failing:
- allocateRenderResourcesAndReturnError returning an error (see below).
- AudioUnitRender returning 49 during audio pulling (with error: "The operation couldn’t be completed. (OSStatus error 49.)").
- Complete freeze of the main thread, blocking the UI.
In allocateRenderResourcesAndReturnError, the NSError passed in the completionHandler block shows the following:
Cannot async instantiate instrument/generator: Couldn’t communicate with a helper application. (au=0x0)
Console logs:
Error: Session <__NSConcreteUUID 0x1334d1d50> D6068E40-5B4C-4BE5-8993-972796FCD56F was unable to communicate with the remote service: Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named xxx.xxxxxxx.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid." UserInfo={NSDebugDescription=The connection to service named xxx.xxxxxx.xxxx.viewservice was interrupted, but the message was sent over an additional proxy and therefore this proxy has become invalid.}
More debug follows:
[739:88058] plugin xxx.xxxxx.xxxx interrupted
[739:88029] 11:46:06.091 WARNING: [0x16e087000] 316: Extension request interrupted! (AU likely crashed. 0x12f9cc760 0x13390cd90)
[739:88029] Received kAudioComponentInstanceInvalidationNotification: auAudioUnit <AUAudioUnit_XH: 0x13390cd90>, audioUnit 0x0
I am wondering the following:
- Is it safe to instanciate AUAudioUnit instances via [AUAudioUnit instantiateWithComponentDescription: options: completionHandler:] on a thread that is not the main one? [Update: I think it's fine, tried both on the main thread and my worker thread with similar results].
- Is it safe to call allocateRenderResourcesAndReturnError on a thread that is not the main one? [Update: I think it's fine, tried both on the main thread and my worker thread with similar results].
- Is it possible that my host, by quickly instanciating AUv3 instances, somewhat triggers race conditions in the AUv3 plugin code? Again, some plugins will load just fine, every time.
Is there any other threading considerations that should be absolutely respected in order to avoid this random plugin client crashes, main thread freezing and instanciation issues?
Thank you for your help.
Mathieu.