# AudioProcessorValueTreeState::Listener crashes \[SOLVED\]

**URL:** <https://forum.juce.com/t/audioprocessorvaluetreestate-listener-crashes-solved/33858>\
**Category:** General JUCE discussion\
**Created:** [June 12, 2019, 11:01am UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-listener-crashes-solved/33858 "2019-06-12T11:01:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheWaveWarden](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thewavewarden/32/13708_2.png) [@TheWaveWarden](https://forum.juce.com/u/TheWaveWarden)\
**Post date:** [June 12, 2019, 11:01am UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-listener-crashes-solved/33858/1 "2019-06-12T11:01:03Z")

</div>

I’m trying to update a component when the value is changed by the host, so I mad it a AudioProcessorValueTreeState::Listener (has a nice ring to it :D)

```auto
for (int i = 0; i < N_ROWS; ++i) {
    m_value_tree.addParameterListener("amount_1_[" + std::to_string(i) + "]", &(m_amount_1[i]));
}

```

But the plugin crashes when I change the param, which lets me to believe that the pointer is somehow invalid.

Now this is tricky to debug: I need a host able to change the parameter (so the JUCE host won’t cut it) and Bitwig-Studio doesn’t give me any output. Furthermore, I can’t check the pointer, because the call happens somewhere inside AudioProcessorValueTreeState.

Any idea what might be wrong?

---

<div class="post-metadata">

**Author:** ![TheWaveWarden](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thewavewarden/32/13708_2.png) [@TheWaveWarden](https://forum.juce.com/u/TheWaveWarden)\
**Post date:** [June 12, 2019, 11:45am UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-listener-crashes-solved/33858/2 "2019-06-12T11:45:52Z")

</div>

some further research gave that the pointer to the component somehow changed between the constructor (where the listener is set) and operation - making it a void pointer.

I think I’ve dealt with a similar problem before, but then I hacked a way around it.  
What could be causing the pointer to change in between?

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [June 12, 2019, 12:00pm UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-listener-crashes-solved/33858/3 "2019-06-12T12:00:26Z")

</div>

Where are you adding the listener? Are you definitely removing the listener again, when the observer is deleted?

---

<div class="post-metadata">

**Author:** ![TheWaveWarden](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thewavewarden/32/13708_2.png) [@TheWaveWarden](https://forum.juce.com/u/TheWaveWarden)\
**Post date:** [June 12, 2019, 12:17pm UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-listener-crashes-solved/33858/4 "2019-06-12T12:17:30Z")

</div>

I’m adding the listener in the constructor of the Editor (rather a subcomponent, but its around the same time).

> [@reuk](#):
>
> Are you definitely removing the listener again, when the observer is deleted?

deleted? Will the editor be deleted before end of lifetime?

---

<div class="post-metadata">

**Author:** ![TheWaveWarden](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thewavewarden/32/13708_2.png) [@TheWaveWarden](https://forum.juce.com/u/TheWaveWarden)\
**Post date:** [June 12, 2019, 12:27pm UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-listener-crashes-solved/33858/5 "2019-06-12T12:27:40Z")

</div>

> [@reuk](#):
>
> Where are you adding the listener? Are you definitely removing the listener again, when the observer is deleted?

Ok yes this indeed was the problem… I’m still wondering though why the AudioPluginEditor will be deleted in between.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [June 12, 2019, 12:29pm UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-listener-crashes-solved/33858/6 "2019-06-12T12:29:24Z")

</div>

The editor isn’t guaranteed to exist for the duration of the AudioProcessor’s lifetime. For example, when you open the plugin window, the editor will be created, and when you close the plugin window, the editor will be destroyed, but the AudioProcessor will still exist. It’s important to make sure that your processor behaves properly, whether or not the editor exists.

---

<div class="post-metadata">

**Author:** ![TheWaveWarden](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thewavewarden/32/13708_2.png) [@TheWaveWarden](https://forum.juce.com/u/TheWaveWarden)\
**Post date:** [June 12, 2019, 12:41pm UTC](https://forum.juce.com/t/audioprocessorvaluetreestate-listener-crashes-solved/33858/7 "2019-06-12T12:41:08Z")

</div>

ok that’s quite the information to swallow… Thanks for your help though! 🙂

_heads off to recode half a plugin_
