Plugin Host crashes on exit with Kontakt 5 AU

When I load the Kontakt 5 AudioUnit in JUCE’s Plugin Host example app, I can use the plugin, but it crashes when I exit the Plugin Host. The VST version doesn’t cause it to crash. I’ve noticed similarly random crashes with other AudioUnits, but I’m choosing Kontakt here because it’s well-established and something that should work.

I’m not doing anything in the Kontakt GUI, just loading the AU. Sometimes, a message box saying “Error: Memory corruption” is showing very briefly before the crash.

How can I fix this? I realize that this may or may not be JUCE’s fault, there could be something wrong with NI’s code, and the code of other 3rd party plugin vendors. But in any case, Kontakt is so popular that users expect it to work. You can’t really sell a product that hosts plugins but cannot host Kontakt.

It crashes in different parts, and on different threads, but it never exits cleanly. When I run it from Xcode, it breaks in juce_AudioUnitPluginFormat.mm, at the call to AudioComponentInstanceDispose. Below are some call stacks from crash reports:

Thread 6 Crashed:: Built-in Output
0   Kontakt 5.MusicDevice.component 0x000000010d0894eb NI::UIA::Application::getApplication() + 27
1   Kontakt 5.MusicDevice.component 0x000000010d167521 NI::AB::InterfaceBase::processAudio() + 113
2   Kontakt 5.MusicDevice.component 0x000000010d162c9d NI::AB::InterfaceAU::Render(unsigned int&, AudioTimeStamp const&, unsigned int) + 3325
3   Kontakt 5.MusicDevice.component 0x000000010d03a863 AUBase::DoRenderBus(unsigned int&, AudioTimeStamp const&, unsigned int, AUOutputElement*, unsigned int, AudioBufferList&) + 127
4   Kontakt 5.MusicDevice.component 0x000000010d039466 AUBase::DoRender(unsigned int&, AudioTimeStamp const&, unsigned int, unsigned int, AudioBufferList&) + 438
5   Kontakt 5.MusicDevice.component 0x000000010d03bf9a AUBase::ComponentEntryDispatch(ComponentParameters*, AUBase*) + 882
6   Kontakt 5.MusicDevice.component 0x000000010cd91fb8 NIAudioUnitSynthEntry + 360
7   com.apple.audio.toolbox.AudioToolbox    0x00007fff9546b46d _AT_AudioUnitRender + 215
8   com.roli.pluginhost             0x00000001059fcbfc juce::AudioUnitPluginInstance::processBlock(juce::AudioBuffer<float>&, juce::MidiBuffer&) + 748 (juce_AudioUnitPluginFormat.mm:616)
9   com.roli.pluginhost             0x0000000105a07186 juce::GraphRenderingOps::ProcessBufferOp::callProcess(juce::AudioBuffer<float>&, juce::MidiBuffer&) + 70 (juce_AudioProcessorGraph.cpp:273)
10  com.roli.pluginhost             0x0000000105a070d4 void juce::GraphRenderingOps::ProcessBufferOp::perform<float>(juce::AudioBuffer<float>&, juce::OwnedArray<juce::MidiBuffer, juce::DummyCriticalSection> const&, int) + 276 (juce_AudioProcessorGraph.cpp:267)
11  com.roli.pluginhost             0x0000000105a06d56 juce::GraphRenderingOps::AudioGraphRenderingOp<juce::GraphRenderingOps::ProcessBufferOp>::perform(juce::AudioBuffer<float>&, juce::OwnedArray<juce::MidiBuffer, juce::DummyCriticalSection> const&, int) + 54 (juce_AudioProcessorGraph.cpp:86)
12  com.roli.pluginhost             0x00000001059ea218 void juce::AudioProcessorGraph::processAudio<float>(juce::AudioBuffer<float>&, juce::MidiBuffer&) + 376 (juce_AudioProcessorGraph.cpp:1457)
13  com.roli.pluginhost             0x00000001059b6515 juce::AudioProcessorGraph::processBlock(juce::AudioBuffer<float>&, juce::MidiBuffer&) + 37 (juce_AudioProcessorGraph.cpp:1481)
14  com.roli.pluginhost             0x0000000105a79343 juce::AudioProcessorPlayer::audioDeviceIOCallback(float const**, int, float**, int, int) + 1427 (juce_AudioProcessorPlayer.cpp:198)
15  com.roli.pluginhost             0x000000010595f7f1 juce::AudioDeviceManager::audioDeviceIOCallbackInt(float const**, int, float**, int, int) + 705 (juce_AudioDeviceManager.cpp:796)
16  com.roli.pluginhost             0x000000010596839f juce::AudioDeviceManager::CallbackHandler::audioDeviceIOCallback(float const**, int, float**, int, int) + 63 (juce_AudioDeviceManager.cpp:57)
17  com.roli.pluginhost             0x0000000105974557 juce::CoreAudioClasses::AudioIODeviceCombiner::run() + 1063 (juce_mac_CoreAudio.cpp:1427)
18  com.roli.pluginhost             0x000000010597471c non-virtual thunk to juce::CoreAudioClasses::AudioIODeviceCombiner::run() + 28 (juce_mac_CoreAudio.cpp:1389)
19  com.roli.pluginhost             0x0000000105abf48a juce::Thread::threadEntryPoint() + 362 (juce_Thread.cpp:102)
20  com.roli.pluginhost             0x0000000105abf785 juce::juce_threadEntryPoint(void*) + 21 (juce_Thread.cpp:118)
21  com.roli.pluginhost             0x0000000105addd4e threadEntryProc + 30 (juce_posix_SharedCode.h:905)
22  libsystem_pthread.dylib         0x00007fff960ba05a _pthread_body + 131
23  libsystem_pthread.dylib         0x00007fff960b9fd7 _pthread_start + 176
24  libsystem_pthread.dylib         0x00007fff960b73ed thread_start + 13

And a different time:

Thread 0 Crashed:: Juce Message Thread  Dispatch queue: com.apple.main-thread
0   ???                             0x00007fff7b8ae300 _thread + 0
1   com.apple.HIToolbox             0x00007fff8b4cf42a HIObject::EventHook(OpaqueEventHandlerCallRef*, OpaqueEventRef*, void*) + 128
2   com.apple.HIToolbox             0x00007fff8b4ceb6c DispatchEventToHandlers(EventTargetRec*, OpaqueEventRef*, HandlerCallRec*) + 1260
3   com.apple.HIToolbox             0x00007fff8b4cdfae SendEventToEventTargetInternal(OpaqueEventRef*, OpaqueEventTargetRef*, HandlerCallRec*) + 386
4   com.apple.HIToolbox             0x00007fff8b4cde22 SendEventToEventTargetWithOptions + 43
5   com.apple.HIToolbox             0x00007fff8b4d6311 HIObject::Destruct() + 123
6   com.apple.CoreFoundation        0x00007fff8e23ee20 CFRelease + 416
7   com.apple.HIToolbox             0x00007fff8b4d601b _ReleaseMenu(MenuData*) + 9
8   com.apple.HIToolbox             0x00007fff8b4d5fe0 ReleaseRootMenus(RootMenus*) + 50
9   com.apple.HIToolbox             0x00007fff8b4d5f9d _MenuIterRelease + 14
10  com.apple.HIToolbox             0x00007fff8b4eb96d HIMenuBarView::EnsureBarLayout() + 59
11  com.apple.HIToolbox             0x00007fff8b5264fa HIMenuBarView::SetFocusPartSelf(short, unsigned char, short*) + 30
12  com.apple.HIToolbox             0x00007fff8b5264b2 HIView::SendSetFocusPart(short, unsigned char, unsigned char, short*) + 324
13  com.apple.HIToolbox             0x00007fff8b5262c2 HIView::SetFocusPartInternal(short, unsigned char, unsigned char, short*, short, unsigned char, unsigned char) + 86
14  com.apple.HIToolbox             0x00007fff8b5260cb HIView::SetFocusPart(short, unsigned char, unsigned char, unsigned int, FocusData*) + 241
15  com.apple.HIToolbox             0x00007fff8b525f48 HIViewSetFocus + 181
16  com.apple.HIToolbox             0x00007fff8b525e90 SetKeyboardFocus + 18
17  com.apple.HIToolbox             0x00007fff8b4d7592 MBWindows::ForEachDisplayWindowDo(void (OpaqueWindowPtr*, unsigned int, unsigned char) block_pointer) + 160
18  com.apple.HIToolbox             0x00007fff8b4d766c ForEachMenuBarViewDo + 93
19  com.apple.HIToolbox             0x00007fff8b525c9d _HiliteMenuTitle(MenuData*, MenuData*, unsigned int, unsigned char) + 100
20  com.apple.HIToolbox             0x00007fff8b525c26 _HiliteMenuTitleOnDisplay + 108
21  com.apple.AppKit                0x00007fff924e2447 unhighlightMenuBarAtTime + 99
22  com.apple.AppKit                0x00007fff924e232b _NSUnhighlightCarbonMenu + 94
23  com.apple.AppKit                0x00007fff924df4a2 -[NSApplication _commonBeginModalSessionForWindow:relativeToWindow:modalDelegate:didEndSelector:contextInfo:] + 1352
24  com.apple.AppKit                0x00007fff924def47 -[NSApplication beginModalSessionForWindow:] + 37
25  com.apple.AppKit                0x00007fff924dee61 -[NSApplication runModalForWindow:] + 98
26  com.apple.AppKit                0x00007fff92590953 -[NSAlert runModal] + 144
27  Kontakt 5.MusicDevice.component 0x0000000110592f62 NI::GP::Message::show(NI::GP::CharSequence<unsigned short> const&, NI::GP::Message::eType, NI::GP::Message::eButton, NI::GP::Message::eIcon, unsigned short const*) + 1714
28  Kontakt 5.MusicDevice.component 0x0000000110a568e2 BMessage::ShowInternal(BString const&, NI::GP::Message::eIcon, NI::GP::Message::eType, NI::GP::Message::eButton) + 162
29  Kontakt 5.MusicDevice.component 0x0000000110a567b7 BMessage::Show(BString const&, BMessage::eIcon, NI::GP::Message::eType, NI::GP::Message::eButton) + 103
30  Kontakt 5.MusicDevice.component 0x0000000110a6698c BPoolMemCorruptionError + 60
31  Kontakt 5.MusicDevice.component 0x0000000110a547f7 hmm_free + 775
32  Kontakt 5.MusicDevice.component 0x0000000110a6579d BPoolMem::Free(void*) + 77
33  Kontakt 5.MusicDevice.component 0x0000000110a7dc39 BString::operator=(char const*) + 41
34  Kontakt 5.MusicDevice.component 0x0000000110b81a82 BOutputConfiguration::OutputPartition::SetName(NI::GP::String const&) + 66
35  Kontakt 5.MusicDevice.component 0x0000000110adbf28 BOutputConfiguration::InitializeMinimumStereo() + 328
36  Kontakt 5.MusicDevice.component 0x0000000110adcb0c BBank::DoResetParameters() + 28
37  Kontakt 5.MusicDevice.component 0x0000000110adddfa BBank::Clear() + 58
38  Kontakt 5.MusicDevice.component 0x0000000110b036f7 BEngine::ShutdownEngine(bool) + 71
39  Kontakt 5.MusicDevice.component 0x00000001102a8a09 non-virtual thunk to BPlugin::deInit() + 89
40  Kontakt 5.MusicDevice.component 0x0000000110560b60 ComponentBase::ComponentEntryDispatch(ComponentParameters*, ComponentBase*) + 52
41  Kontakt 5.MusicDevice.component 0x000000011055efc6 AUBase::ComponentEntryDispatch(ComponentParameters*, AUBase*) + 926
42  Kontakt 5.MusicDevice.component 0x00000001102b4f80 NIAudioUnitSynthEntry + 304
43  com.apple.CoreServices.CarbonCore   0x00007fff8c65585e CallComponentClose + 46
44  com.apple.CoreServices.CarbonCore   0x00007fff8c655794 CloseComponentInternal(ComponentInstanceRecord*) + 98
45  com.apple.CoreServices.CarbonCore   0x00007fff8c65571f CloseComponent + 33
46  com.apple.audio.toolbox.AudioToolbox    0x00007fff9553d29f AudioComponentMgr::DisposeInstance(ComponentInstanceRecord*) + 41
47  com.roli.pluginhost             0x0000000108f6b615 juce::AudioUnitPluginInstance::cleanup() + 117
48  com.roli.pluginhost             0x0000000108f6b2a1 juce::AudioUnitPluginInstance::~AudioUnitPluginInstance() + 289
49  com.roli.pluginhost             0x0000000108f1f355 juce::AudioUnitPluginInstance::~AudioUnitPluginInstance() + 21
50  com.roli.pluginhost             0x0000000108f1f379 juce::AudioUnitPluginInstance::~AudioUnitPluginInstance() + 25
51  com.roli.pluginhost             0x0000000108f6f841 juce::ContainerDeletePolicy<juce::AudioProcessor>::destroy(juce::AudioProcessor*) + 65
52  com.roli.pluginhost             0x0000000108f6f7e4 juce::ScopedPointer<juce::AudioProcessor>::~ScopedPointer() + 20
53  com.roli.pluginhost             0x0000000108f0ee15 juce::ScopedPointer<juce::AudioProcessor>::~ScopedPointer() + 21
54  com.roli.pluginhost             0x0000000108f8f9c7 juce::AudioProcessorGraph::Node::~Node() + 71
55  com.roli.pluginhost             0x0000000108f210f5 juce::AudioProcessorGraph::Node::~Node() + 21
56  com.roli.pluginhost             0x0000000108f21119 juce::AudioProcessorGraph::Node::~Node() + 25
57  com.roli.pluginhost             0x0000000108e22721 juce::ContainerDeletePolicy<juce::AudioProcessorGraph::Node>::destroy(juce::AudioProcessorGraph::Node*) + 65
58  com.roli.pluginhost             0x0000000108e2260c juce::ReferenceCountedObjectPtr<juce::AudioProcessorGraph::Node>::decIfNotNull(juce::AudioProcessorGraph::Node*) + 60
59  com.roli.pluginhost             0x0000000108e225c8 juce::ReferenceCountedObjectPtr<juce::AudioProcessorGraph::Node>::~ReferenceCountedObjectPtr() + 24
60  com.roli.pluginhost             0x0000000108e21615 juce::ReferenceCountedObjectPtr<juce::AudioProcessorGraph::Node>::~ReferenceCountedObjectPtr() + 21
61  com.roli.pluginhost             0x0000000108f29fab juce::GraphRenderingOps::ProcessBufferOp::~ProcessBufferOp() + 107
62  com.roli.pluginhost             0x0000000108f29ce5 juce::GraphRenderingOps::ProcessBufferOp::~ProcessBufferOp() + 21
63  com.roli.pluginhost             0x0000000108f29d09 juce::GraphRenderingOps::ProcessBufferOp::~ProcessBufferOp() + 25
64  com.roli.pluginhost             0x0000000108ed89b7 juce::deleteRenderOpArray(juce::Array<void*, juce::DummyCriticalSection, 0>&) + 87
65  com.roli.pluginhost             0x0000000108ed7b41 juce::AudioProcessorGraph::clearRenderingSequence() + 97
66  com.roli.pluginhost             0x0000000108ed7970 juce::AudioProcessorGraph::~AudioProcessorGraph() + 48
67  com.roli.pluginhost             0x0000000108ed7be5 juce::AudioProcessorGraph::~AudioProcessorGraph() + 21
68  com.roli.pluginhost             0x0000000108e1e10f FilterGraph::~FilterGraph() + 79
69  com.roli.pluginhost             0x0000000108e1e185 FilterGraph::~FilterGraph() + 21
70  com.roli.pluginhost             0x0000000108e2579b GraphDocumentComponent::~GraphDocumentComponent() + 427
71  com.roli.pluginhost             0x0000000108e25835 GraphDocumentComponent::~GraphDocumentComponent() + 21
72  com.roli.pluginhost             0x0000000108e25859 GraphDocumentComponent::~GraphDocumentComponent() + 25
73  com.roli.pluginhost             0x0000000109276692 juce::Component::SafePointer<juce::Component>::deleteAndZero() + 50
74  com.roli.pluginhost             0x00000001091f7153 juce::ResizableWindow::clearContentComponent() + 51
75  com.roli.pluginhost             0x0000000108e3044e MainHostWindow::~MainHostWindow() + 398
76  com.roli.pluginhost             0x0000000108e30645 MainHostWindow::~MainHostWindow() + 21
77  com.roli.pluginhost             0x0000000108e30759 MainHostWindow::~MainHostWindow() + 25
78  com.roli.pluginhost             0x0000000108e2eb01 juce::ContainerDeletePolicy<MainHostWindow>::destroy(MainHostWindow*) + 65
79  com.roli.pluginhost             0x0000000108e2ebc0 juce::ScopedPointer<MainHostWindow>::operator=(MainHostWindow*) + 64
80  com.roli.pluginhost             0x0000000108e2e36a PluginHostApp::shutdown() + 42
81  com.roli.pluginhost             0x0000000109098891 juce::JUCEApplicationBase::shutdownApp() + 177
82  com.roli.pluginhost             0x0000000109098787 juce::JUCEApplicationBase::appWillTerminateByForce() + 71
83  com.roli.pluginhost             0x00000001090a8a39 juce::AppDelegate::AppDelegateClass::applicationWillTerminate(objc_object*, objc_selector*, NSNotification*) + 25
84  com.apple.CoreFoundation        0x00007fff8e34645c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
85  com.apple.CoreFoundation        0x00007fff8e236634 _CFXNotificationPost + 3140
86  com.apple.Foundation            0x00007fff8d3e7aa1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
87  com.apple.AppKit                0x00007fff9260695f -[NSApplication terminate:] + 1759
88  libsystem_trace.dylib           0x00007fff8a3d9cd7 _os_activity_initiate + 75
89  com.apple.AppKit                0x00007fff924daeb1 -[NSApplication sendAction:to:from:] + 452
90  com.apple.AppKit                0x00007fff924dac4e -[NSMenuItem _corePerformAction] + 382
91  com.apple.AppKit                0x00007fff924da97c -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 114
92  libsystem_trace.dylib           0x00007fff8a3d9cd7 _os_activity_initiate + 75
93  com.apple.AppKit                0x00007fff924d98ad -[NSMenu performKeyEquivalent:] + 359
94  com.apple.AppKit                0x00007fff924d8a6f -[NSApplication _handleKeyEquivalent:] + 920
95  com.apple.AppKit                0x00007fff923e383a -[NSApplication sendEvent:] + 4080
96  com.apple.AppKit                0x00007fff9230cb68 -[NSApplication run] + 711
97  com.roli.pluginhost             0x0000000109099313 juce::MessageManager::runDispatchLoop() + 147
98  com.roli.pluginhost             0x00000001090991fa juce::JUCEApplicationBase::main() + 394
99  com.roli.pluginhost             0x000000010909900c juce::JUCEApplicationBase::main(int, char const**) + 60
100 com.roli.pluginhost             0x0000000108e2dcb3 main + 51
101 libdyld.dylib                   0x00007fff9089b5c9 start + 1

And yet another part of the code:

Thread 0 Crashed:: Juce Message Thread  Dispatch queue: com.apple.main-thread
0   Kontakt 5.MusicDevice.component 0x000000010d8fda46 NI::GP::CriticalSection::enter() + 6
1   Kontakt 5.MusicDevice.component 0x000000010dddf77b BPoolMem::Free(void*) + 43
2   Kontakt 5.MusicDevice.component 0x000000010ddf7c39 BString::operator=(char const*) + 41
3   Kontakt 5.MusicDevice.component 0x000000010defba82 BOutputConfiguration::OutputPartition::SetName(NI::GP::String const&) + 66
4   Kontakt 5.MusicDevice.component 0x000000010de55f28 BOutputConfiguration::InitializeMinimumStereo() + 328
5   Kontakt 5.MusicDevice.component 0x000000010de56b0c BBank::DoResetParameters() + 28
6   Kontakt 5.MusicDevice.component 0x000000010de57dfa BBank::Clear() + 58
7   Kontakt 5.MusicDevice.component 0x000000010de7d6f7 BEngine::ShutdownEngine(bool) + 71
8   Kontakt 5.MusicDevice.component 0x000000010d622a09 non-virtual thunk to BPlugin::deInit() + 89
9   Kontakt 5.MusicDevice.component 0x000000010d8dab60 ComponentBase::ComponentEntryDispatch(ComponentParameters*, ComponentBase*) + 52
10  Kontakt 5.MusicDevice.component 0x000000010d8d8fc6 AUBase::ComponentEntryDispatch(ComponentParameters*, AUBase*) + 926
11  Kontakt 5.MusicDevice.component 0x000000010d62ef80 NIAudioUnitSynthEntry + 304
12  com.apple.CoreServices.CarbonCore   0x00007fff8c65585e CallComponentClose + 46
13  com.apple.CoreServices.CarbonCore   0x00007fff8c655794 CloseComponentInternal(ComponentInstanceRecord*) + 98
14  com.apple.CoreServices.CarbonCore   0x00007fff8c65571f CloseComponent + 33
15  com.apple.audio.toolbox.AudioToolbox    0x00007fff9553d29f AudioComponentMgr::DisposeInstance(ComponentInstanceRecord*) + 41
16  com.roli.pluginhost             0x00000001062e5615 juce::AudioUnitPluginInstance::cleanup() + 117 (juce_AudioUnitPluginFormat.mm:391)
17  com.roli.pluginhost             0x00000001062e52a1 juce::AudioUnitPluginInstance::~AudioUnitPluginInstance() + 289 (juce_AudioUnitPluginFormat.mm:365)
18  com.roli.pluginhost             0x0000000106299355 juce::AudioUnitPluginInstance::~AudioUnitPluginInstance() + 21 (juce_AudioUnitPluginFormat.mm:374)
19  com.roli.pluginhost             0x0000000106299379 juce::AudioUnitPluginInstance::~AudioUnitPluginInstance() + 25 (juce_AudioUnitPluginFormat.mm:336)
20  com.roli.pluginhost             0x00000001062e9841 juce::ContainerDeletePolicy<juce::AudioProcessor>::destroy(juce::AudioProcessor*) + 65 (juce_ContainerDeletePolicy.h:59)
21  com.roli.pluginhost             0x00000001062e97e4 juce::ScopedPointer<juce::AudioProcessor>::~ScopedPointer() + 20 (juce_ScopedPointer.h:107)
22  com.roli.pluginhost             0x0000000106288e15 juce::ScopedPointer<juce::AudioProcessor>::~ScopedPointer() + 21 (juce_ScopedPointer.h:107)
23  com.roli.pluginhost             0x00000001063099c7 juce::AudioProcessorGraph::Node::~Node() + 71 (juce_AudioProcessorGraph.h:60)
24  com.roli.pluginhost             0x000000010629b0f5 juce::AudioProcessorGraph::Node::~Node() + 21 (juce_AudioProcessorGraph.h:60)
25  com.roli.pluginhost             0x000000010629b119 juce::AudioProcessorGraph::Node::~Node() + 25 (juce_AudioProcessorGraph.h:60)
26  com.roli.pluginhost             0x000000010619c721 juce::ContainerDeletePolicy<juce::AudioProcessorGraph::Node>::destroy(juce::AudioProcessorGraph::Node*) + 65 (juce_ContainerDeletePolicy.h:59)
27  com.roli.pluginhost             0x000000010619c60c juce::ReferenceCountedObjectPtr<juce::AudioProcessorGraph::Node>::decIfNotNull(juce::AudioProcessorGraph::Node*) + 60 (juce_ReferenceCountedObject.h:374)
28  com.roli.pluginhost             0x000000010619c5c8 juce::ReferenceCountedObjectPtr<juce::AudioProcessorGraph::Node>::~ReferenceCountedObjectPtr() + 24 (juce_ReferenceCountedObject.h:336)
29  com.roli.pluginhost             0x000000010619b615 juce::ReferenceCountedObjectPtr<juce::AudioProcessorGraph::Node>::~ReferenceCountedObjectPtr() + 21 (juce_ReferenceCountedObject.h:336)
30  com.roli.pluginhost             0x00000001062a3fab juce::GraphRenderingOps::ProcessBufferOp::~ProcessBufferOp() + 107 (juce_AudioProcessorGraph.cpp:238)
31  com.roli.pluginhost             0x00000001062a3ce5 juce::GraphRenderingOps::ProcessBufferOp::~ProcessBufferOp() + 21 (juce_AudioProcessorGraph.cpp:238)
32  com.roli.pluginhost             0x00000001062a3d09 juce::GraphRenderingOps::ProcessBufferOp::~ProcessBufferOp() + 25 (juce_AudioProcessorGraph.cpp:238)
33  com.roli.pluginhost             0x00000001062529b7 juce::deleteRenderOpArray(juce::Array<void*, juce::DummyCriticalSection, 0>&) + 87 (juce_AudioProcessorGraph.cpp:1290)
34  com.roli.pluginhost             0x0000000106251b41 juce::AudioProcessorGraph::clearRenderingSequence() + 97 (juce_AudioProcessorGraph.cpp:1303)
35  com.roli.pluginhost             0x0000000106251970 juce::AudioProcessorGraph::~AudioProcessorGraph() + 48 (juce_AudioProcessorGraph.cpp:1044)
36  com.roli.pluginhost             0x0000000106251be5 juce::AudioProcessorGraph::~AudioProcessorGraph() + 21 (juce_AudioProcessorGraph.cpp:1046)
37  com.roli.pluginhost             0x000000010619810f FilterGraph::~FilterGraph() + 79 (FilterGraph.cpp:54)
38  com.roli.pluginhost             0x0000000106198185 FilterGraph::~FilterGraph() + 21 (FilterGraph.cpp:54)
39  com.roli.pluginhost             0x000000010619f79b GraphDocumentComponent::~GraphDocumentComponent() + 427 (GraphEditorPanel.cpp:1128)
40  com.roli.pluginhost             0x000000010619f835 GraphDocumentComponent::~GraphDocumentComponent() + 21 (GraphEditorPanel.cpp:1128)
41  com.roli.pluginhost             0x000000010619f859 GraphDocumentComponent::~GraphDocumentComponent() + 25 (GraphEditorPanel.cpp:1117)
42  com.roli.pluginhost             0x00000001065f0692 juce::Component::SafePointer<juce::Component>::deleteAndZero() + 50 (juce_Component.h:2140)
43  com.roli.pluginhost             0x0000000106571153 juce::ResizableWindow::clearContentComponent() + 51 (juce_ResizableWindow.cpp:100)
44  com.roli.pluginhost             0x00000001061aa44e MainHostWindow::~MainHostWindow() + 398 (MainHostWindow.cpp:137)
45  com.roli.pluginhost             0x00000001061aa645 MainHostWindow::~MainHostWindow() + 21 (MainHostWindow.cpp:138)
46  com.roli.pluginhost             0x00000001061aa759 MainHostWindow::~MainHostWindow() + 25 (MainHostWindow.cpp:124)
47  com.roli.pluginhost             0x00000001061a8b01 juce::ContainerDeletePolicy<MainHostWindow>::destroy(MainHostWindow*) + 65 (juce_ContainerDeletePolicy.h:59)
48  com.roli.pluginhost             0x00000001061a8bc0 juce::ScopedPointer<MainHostWindow>::operator=(MainHostWindow*) + 64 (juce_ScopedPointer.h:151)
49  com.roli.pluginhost             0x00000001061a836a PluginHostApp::shutdown() + 42 (HostStartup.cpp:102)
50  com.roli.pluginhost             0x0000000106412891 juce::JUCEApplicationBase::shutdownApp() + 177 (juce_ApplicationBase.cpp:298)
51  com.roli.pluginhost             0x0000000106412787 juce::JUCEApplicationBase::appWillTerminateByForce() + 71 (juce_ApplicationBase.cpp:56)
52  com.roli.pluginhost             0x0000000106422a39 juce::AppDelegate::AppDelegateClass::applicationWillTerminate(objc_object*, objc_selector*, NSNotification*) + 25 (juce_mac_MessageManager.mm:145)
53  com.apple.CoreFoundation        0x00007fff8e34645c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
54  com.apple.CoreFoundation        0x00007fff8e236634 _CFXNotificationPost + 3140
55  com.apple.Foundation            0x00007fff8d3e7aa1 -[NSNotificationCenter postNotificationName:object:userInfo:] + 66
56  com.apple.AppKit                0x00007fff9260695f -[NSApplication terminate:] + 1759
57  libsystem_trace.dylib           0x00007fff8a3d9cd7 _os_activity_initiate + 75
58  com.apple.AppKit                0x00007fff924daeb1 -[NSApplication sendAction:to:from:] + 452
59  com.apple.AppKit                0x00007fff924dac4e -[NSMenuItem _corePerformAction] + 382
60  com.apple.AppKit                0x00007fff924da97c -[NSCarbonMenuImpl performActionWithHighlightingForItemAtIndex:] + 114
61  libsystem_trace.dylib           0x00007fff8a3d9cd7 _os_activity_initiate + 75
62  com.apple.AppKit                0x00007fff924d98ad -[NSMenu performKeyEquivalent:] + 359
63  com.apple.AppKit                0x00007fff924d8a6f -[NSApplication _handleKeyEquivalent:] + 920
64  com.apple.AppKit                0x00007fff923e383a -[NSApplication sendEvent:] + 4080
65  com.apple.AppKit                0x00007fff9230cb68 -[NSApplication run] + 711
66  com.roli.pluginhost             0x0000000106413313 juce::MessageManager::runDispatchLoop() + 147 (juce_mac_MessageManager.mm:251)
67  com.roli.pluginhost             0x00000001064131fa juce::JUCEApplicationBase::main() + 394 (juce_ApplicationBase.cpp:240)
68  com.roli.pluginhost             0x000000010641300c juce::JUCEApplicationBase::main(int, char const**) + 60 (juce_ApplicationBase.cpp:218)
69  com.roli.pluginhost             0x00000001061a7cb3 main + 51 (HostStartup.cpp:133)
70  libdyld.dylib                   0x00007fff9089b5c9 start + 1

Hmmmm seems like Kontakt is still processing audio when you try to delete it. Can you try adding the following two lines

const ScopedLock callbackLock (getCallbackLock());
suspendProcessing (true);

just after juce_AudioUnitPluginFormat.mm:378. That would ensure that the plug-in cannot render while being cleaned up.

I just added the two lines where you said, and it still crashes: The Juce Message Thread breaks with a BAD_ACCESS at the AudioComponentInstanceDispose line (in cleanup).

Thanks for looking into it though. Your fix could possibly solve the first crash report I posted, where it crashes on the Audio I/O thread.

I’ll install Kontakt next week and try to reproduce this. I think this looks like a JUCE bug and not like Kontakt bug. Either way, we need to fix this (or find a suitable workaround).

This should be fixed for the audio plugin host on the latest develop branch. If you are writing a hosting app and running into this problem, then you are calling JUCEApplication::quit before you are deleting the AudioPluginInstance running Kontakt 5 AU. To fix this in your host, simply deallocate your plug-in graph/player etc. before calling JUCEApplication::quit.

The reason why Kontakt crashes is that it access the obj-c NSApp object. However, one of the first things JUCEApplication::quit does is to call [NSApp stop]. This seems to confuse NI plug-ins.