# Plugin Host demo - crash bug/thread safety

**URL:** <https://forum.juce.com/t/plugin-host-demo-crash-bug-thread-safety/15116>\
**Category:** General JUCE discussion\
**Created:** [July 14, 2015, 9:23pm UTC](https://forum.juce.com/t/plugin-host-demo-crash-bug-thread-safety/15116 "2015-07-14T21:23:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CowTipper](https://avatars.discourse-cdn.com/v4/letter/c/7c8e57/32.png) [@CowTipper](https://forum.juce.com/u/CowTipper)\
**Post date:** [July 14, 2015, 9:23pm UTC](https://forum.juce.com/t/plugin-host-demo-crash-bug-thread-safety/15116/1 "2015-07-14T21:23:01Z")

</div>

I can get the Plugin Host demo to crash about 1 in 10 times when I repeatedly add a 'MIDI Input'&nbsp;node and delete it again using the GUI.

Deleting the MIDI Input node via the GUI results in this call sequence:

GUI -\> FilterGraph::removeFilter() -\>&nbsp;AudioProcessorGraph::removeNode() -\> ...&nbsp;AudioGraphIOProcessor::setParentGraph(nullptr)

... trouble is that&nbsp;AudioGraphIOProcessor will be running on&nbsp;the audio thread until AudioProcessorGraph gets round to updating the rendering op sequence. &nbsp;The crash happens in&nbsp;AudioGraphIOProcessor::processBlock() when it tries to use the null graph pointer.

Although I'm not&nbsp;aware of all the subtleties, it looks like one possible fix is simply to remove the call to&nbsp;setParentGraph(nullptr) in&nbsp;AudioProcessorGraph::removeNode(). &nbsp;It seems like there's no need for it because the node is about to get deleted&nbsp;once the render op list is swapped and it&nbsp;drops its refcount on the node.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 17, 2015, 12:06pm UTC](https://forum.juce.com/t/plugin-host-demo-crash-bug-thread-safety/15116/2 "2015-07-17T12:06:25Z")

</div>

Thanks.. Yes, it's a subtle one, but I think you're right that just removing the setParentGraph call would do the right thing - I'll sort that out..
