Juce Demo crash in Studio One


#1

Hi Jules,

I think I’ve found a bug in Juce with PreSonus Studio One in Mac. I have reproduced it with the Juce Demo, and I’m using the tip.
Studio One crashes when a project containing an instance of the Juce Demo is open, and another project is opened on top of this. The host only crashes when the Juce Demo GUI is shown in the first project. The second project doesn’t need to have an instance of the Juce Demo or any other plug-in.
I can’t reproduce the crash with non-Juce plug-ins, so it doesn’t seem to be a Studio One issue.

Here’s the crash report:

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

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000000548900ae

VM Regions Near 0x548900ae:
VM_ALLOCATE 000000001f900000-0000000020703000 [ 14.0M] rw-/rwx SM=PRV
–>
__TEXT 000000008fed7000-000000008ff0a000 [ 204K] r-x/rwx SM=COW /usr/lib/dyld

Application Specific Information:
objc_msgSend() selector name: lockFocus

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x911bba87 objc_msgSend + 23
1 com.presonus.cclgui 0x011dc96f CCL::Window::createDrawContext() + 47
2 com.presonus.cclgui 0x012af5eb CCL::MacOS::QuartzDevice::QuartzDevice(CCL::Window*) + 139
3 com.presonus.cclgui 0x011cfc65 CCL::MacOS::QuartzEngine::createWindowDevice(CCL::Window*, void*) + 37
4 com.presonus.cclgui 0x011bc537 CCL::WindowGraphicsDevice::WindowGraphicsDevice(CCL::Window&, CCL::NativeGraphicsDevice*) + 135
5 com.presonus.cclgui 0x011bd457 CCL::Window::getGraphicsDevice(CCL::Point&) + 55
6 com.presonus.cclgui 0x011b5a6b CCL::View::getGraphicsDevice(CCL::Point&) + 75
7 com.presonus.cclgui 0x011b5a6b CCL::View::getGraphicsDevice(CCL::Point&) + 75
8 com.presonus.cclgui 0x011b5a6b CCL::View::getGraphicsDevice(CCL::Point&) + 75
9 com.presonus.cclgui 0x011b5a6b CCL::View::getGraphicsDevice(CCL::Point&) + 75
10 com.presonus.cclgui 0x011b5a6b CCL::View::getGraphicsDevice(CCL::Point&) + 75
11 com.presonus.cclgui 0x011b5a6b CCL::View::getGraphicsDevice(CCL::Point&) + 75
12 com.presonus.cclgui 0x011b5a6b CCL::View::getGraphicsDevice(CCL::Point&) + 75
13 com.presonus.cclgui 0x011b5a6b CCL::View::getGraphicsDevice(CCL::Point&) + 75
14 com.presonus.cclgui 0x011a8fd8 CCL::GraphicsPort::GraphicsPort(CCL::View*) + 168
15 com.presonus.cclgui 0x01294e57 CCL::CompositedRenderer::update(CCL::View*, CCL::ThemeRenderer::UpdateInfo const&) + 71
16 com.presonus.cclgui 0x010db1c7 CCL::Control::updateClient() + 87
17 com.presonus.cclgui 0x010dadb7 CCL::Control::paramChanged() + 119
18 com.presonus.cclgui 0x010daccb CCL::Control::notify(CCL::ISubject*, CCL::IMessage const&) + 107
19 com.presonus.cclgui 0x010dad32 non-virtual thunk to CCL::Control::notify(CCL::ISubject*, CCL::IMessage const&) + 34
20 com.presonus.cclsystem 0x0189e7ef CCL::ObserverList::performSignal(CCL::IMessage const&) + 159
21 com.presonus.cclsystem 0x0189f8e2 non-virtual thunk to CCL::SignalHandler::performSignal(CCL::ISubject*, CCL::IMessage const&) + 114
22 com.presonus.studioone2 0x008c6424 0x1000 + 9196580
23 com.presonus.studioone2 0x007eae2b 0x1000 + 8298027
24 com.presonus.studioone2 0x007eae72 0x1000 + 8298098
25 com.presonus.cclsystem 0x0189e7ef CCL::ObserverList::performSignal(CCL::IMessage const&) + 159
26 com.presonus.cclsystem 0x0189ec70 CCL::SignalHandler::changedCallback(void*, CCL::IMessage*) + 128
27 com.presonus.cclsystem 0x0189f257 CCL::SignalHandler::flush() + 407
28 com.presonus.cclsystem 0x0189f3a4 non-virtual thunk to CCL::SignalHandler::flush() + 20
29 com.presonus.cclgui 0x01140dab CCL::UserInterface::onTimer(CCL::ITimer*) + 59
30 com.presonus.cclgui 0x011410c4 non-virtual thunk to CCL::UserInterface::onTimer(CCL::ITimer*) + 20
31 com.presonus.cclgui 0x01199151 CCL::SystemTimer::task() + 129
32 com.presonus.cclgui 0x01199085 CCL::SystemTimer::serviceTimers() + 117
33 com.presonus.cclgui 0x011d415f serviceTimers() + 31
34 com.presonus.cclgui 0x011d42eb -[CustomApplication sendEvent:] + 155
35 com.rawmaterialsoftware.JuceDemoPlugin 0x1b9c2e61 juce::MessageManager::runDispatchLoopUntil(int) + 561 (juce_mac_MessageManager.mm:274)
36 com.rawmaterialsoftware.JuceDemoPlugin 0x1bc77656 juce::detachComponentFromWindowRef(juce::Component*, void*) + 662 (juce_VST_Wrapper.mm:207)
37 com.rawmaterialsoftware.JuceDemoPlugin 0x1bc72800 JuceVSTWrapper::deleteEditor(bool) + 368 (juce_VST_Wrapper.cpp:1153)
38 com.rawmaterialsoftware.JuceDemoPlugin 0x1bc6f9c0 JuceVSTWrapper::dispatcher(int, int, int, void*, float) + 672 (juce_VST_Wrapper.cpp:1221)
39 com.rawmaterialsoftware.JuceDemoPlugin 0x1bc6cedb AudioEffect::dispatchEffectClass(AEffect*, int, int, int, void*, float) + 219 (audioeffect.cpp:32)
40 com.presonus.vstservice 0x1172f3be 0x11700000 + 193470
41 com.presonus.vstservice 0x11766db5 0x11700000 + 421301
42 com.presonus.vstservice 0x11766e54 0x11700000 + 421460
43 com.presonus.cclgui 0x0110ec0b CCL::PlugInView::removed(CCL::View*) + 43
44 com.presonus.cclgui 0x011b3ec9 CCL::View::removed(CCL::View*) + 185
45 com.presonus.cclgui 0x011b3ec9 CCL::View::removed(CCL::View*) + 185
46 com.presonus.cclgui 0x011b3ec9 CCL::View::removed(CCL::View*) + 185
47 com.presonus.cclgui 0x011b3ec9 CCL::View::removed(CCL::View*) + 185
48 com.presonus.cclgui 0x011b3995 CCL::View::removeView(CCL::View*) + 53
49 com.presonus.cclgui 0x011b3671 CCL::View::removeAll() + 49
50 com.presonus.cclgui 0x011bccfc CCL::Window::~Window() + 332
51 com.presonus.cclgui 0x011dcd33 CCL::PopupWindow::~PopupWindow() + 19
52 com.presonus.cclgui 0x012df6e7 CCL::Unknown::release() + 55
53 com.presonus.cclgui 0x011db8cf CCL::Window::close() + 191
54 com.presonus.cclgui 0x0125e686 CCL::PopupFrameItem::hide() + 134
55 com.presonus.cclgui 0x011fe9e5 CCL::DockPanelItem::hideAll() + 101
56 com.presonus.cclgui 0x0125cd17 CCL::MultiFrameItem::hideAll() + 23
57 com.presonus.cclgui 0x011fe9e5 CCL::DockPanelItem::hideAll() + 101
58 com.presonus.cclgui 0x0125c371 CCL::RootFrameItem::hideAll() + 81
59 com.presonus.cclgui 0x01214443 CCL::Workspace::selectPerspective(CCL::Perspective*) + 51
60 com.presonus.cclgui 0x012146a4 CCL::Workspace::selectPerspective(CCL::IPerspective*) + 132
61 com.presonus.cclgui 0x012146cb non-virtual thunk to CCL::Workspace::selectPerspective(CCL::IPerspective*) + 27
62 com.presonus.studioone2 0x000197df 0x1000 + 100319
63 com.presonus.studioone2 0x00019834 0x1000 + 100404
64 com.presonus.studioone2 0x0077a325 0x1000 + 7836453
65 com.presonus.studioone2 0x0077cbbf 0x1000 + 7846847
66 com.presonus.studioone2 0x0077cd62 0x1000 + 7847266
67 com.presonus.cclsystem 0x0189ecb8 CCL::SignalHandler::messageCallback(void*, CCL::IMessage*) + 40
68 com.presonus.cclsystem 0x0189f257 CCL::SignalHandler::flush() + 407
69 com.presonus.cclsystem 0x0189f3a4 non-virtual thunk to CCL::SignalHandler::flush() + 20
70 com.presonus.cclgui 0x01140dab CCL::UserInterface::onTimer(CCL::ITimer*) + 59
71 com.presonus.cclgui 0x011410c4 non-virtual thunk to CCL::UserInterface::onTimer(CCL::ITimer*) + 20
72 com.presonus.cclgui 0x01199151 CCL::SystemTimer::task() + 129
73 com.presonus.cclgui 0x01199085 CCL::SystemTimer::serviceTimers() + 117
74 com.presonus.cclgui 0x011d415f serviceTimers() + 31
75 com.apple.Foundation 0x93901cd4 __NSFireTimer + 117
76 com.apple.CoreFoundation 0x9651c416 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 22
77 com.apple.CoreFoundation 0x9651bdb5 __CFRunLoopDoTimer + 709
78 com.apple.CoreFoundation 0x96500bc2 __CFRunLoopRun + 1842
79 com.apple.CoreFoundation 0x9650002a CFRunLoopRunSpecific + 378
80 com.apple.CoreFoundation 0x964ffe9b CFRunLoopRunInMode + 123
81 com.apple.HIToolbox 0x91ae4f5a RunCurrentEventLoopInMode + 242
82 com.apple.HIToolbox 0x91ae4bf5 ReceiveNextEventCommon + 162
83 com.apple.HIToolbox 0x91ae4b44 BlockUntilNextEventMatchingListInMode + 88
84 com.apple.AppKit 0x920ff9aa _DPSNextEvent + 724
85 com.apple.AppKit 0x920ff1dc -[NSApplication nextEventMatchingMask:untilDate:inMode:dequeue:] + 119
86 com.apple.AppKit 0x920f563c -[NSApplication run] + 855
87 com.presonus.cclgui 0x011d4a3d non-virtual thunk to CCL::UserInterface::runEventLoop() + 173
88 com.presonus.studioone2 0x00002486 0x1000 + 5254
89 com.presonus.studioone2 0x00096948 0x1000 + 612680
90 com.presonus.studioone2 0x00002355 start + 53
[/code]


JUCE_AUTORELEASEPOOL BAD_ACCESS in VST destructor
#2

Commenting line 206-207 of juce_VST_Wrapper.mm should fix your issue.

Maybe those line should depends on the hosts Jules ?


#3

Lines 206-7?? Are you looking at the latest version of the code?


#4

git trunk
juce\modules\juce_audio_plugin_client\VST\juce_VST_Wrapper.mm
line 206 and 207

for (int i = 20; --i >= 0;)
MessageManager::getInstance()->runDispatchLoopUntil (1);


#5

(Ah sorry, I was looking at the .cpp rather than the .mm)

Those lines are there for a purpose though - it stops other crashes, even if it happens to help in the particular case that you’re talking about here. It may indeed be true that they’re not needed for Studio One, but it’d require some testing to prove that before I could remove them.


#6

FWIW, I test in StudioOne (Mac and Windows) quite a lot and I don’t get crashes. There could be something in the Juce demo, but Juce itself is performing well in StudioOne with no conditional code.


#7

The purpose of that particular bit of code is when you try to quit the host while a plugin window is open - many hosts kill the plugin without allowing its event loop to run, which messes up some internal OS windowing things. So that’d be the thing to test for in studio one before assuming it’s safe.


#8

I tried commenting out those lines, and Studio One doesn’t crash when I open the second project but it does crash when I close the application. Here is the crash report for this new crash:

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

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000040bbf80e

VM Regions Near 0x40bbf80e:
VM_ALLOCATE 000000001e6c5000-000000001f0e8000 [ 10.1M] rw-/rwx SM=PRV
–>
__TEXT 000000008fe8a000-000000008febd000 [ 204K] r-x/rwx SM=COW /usr/lib/dyld

Application Specific Information:
objc_msgSend() selector name: release

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libobjc.A.dylib 0x911bba9c objc_msgSend + 44
1 com.apple.CoreFoundation 0x964d232b CFRelease + 171
2 com.apple.CoreFoundation 0x96512f80 -[__NSArrayI dealloc] + 144
3 libobjc.A.dylib 0x911d48ff -[NSObject release] + 47
4 libobjc.A.dylib 0x911be442 (anonymous namespace)::AutoreleasePoolPage::pop(void*) + 490
5 com.apple.CoreFoundation 0x964fba73 _CFAutoreleasePoolPop + 51
6 com.apple.Foundation 0x938e773d -[NSAutoreleasePool drain] + 122
7 com.apple.AppKit 0x920f56fa -[NSApplication run] + 1045
8 com.presonus.cclgui 0x011d4a3d non-virtual thunk to CCL::UserInterface::runEventLoop() + 173
9 com.presonus.studioone2 0x00002486 0x1000 + 5254
10 com.presonus.studioone2 0x00096948 0x1000 + 612680
11 com.presonus.studioone2 0x00002355 start + 53
[/code]

I have also noticed that the problem only happens in Mac and for the 32bit version. No crash happens with Studio One 64bit or with Windows, either with or without those two lines of code.


#9

Yes, that’s exactly the crash that the original code is there to avoid. As you can see, it crashes in OSX code after the plugin has been unloaded from memory. So the MM dispatch loop is there to allow the OSX windowing stuff to clean up before the plugin is deleted by the host.

This wouldn’t be needed if all hosts allowed a short pause between closing the window and unloading the plugin, but most don’t do that.