# APVTS and state properties

**URL:** <https://forum.juce.com/t/apvts-and-state-properties/48637>\
**Category:** General JUCE discussion\
**Created:** [November 7, 2021, 10:11am UTC](https://forum.juce.com/t/apvts-and-state-properties/48637 "2021-11-07T10:11:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![duvrin](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@duvrin](https://forum.juce.com/u/duvrin)\
**Post date:** [November 7, 2021, 10:11am UTC](https://forum.juce.com/t/apvts-and-state-properties/48637/1 "2021-11-07T10:11:21Z")

</div>

I’m having an issue which seems random and not reproducible. I think I have the general direction but I’d like to know if this makes any sense at all or am I barking at the wrong tree here.

tl;dr: is it safe to use `apvts.state` properties in real time like an AudioProcessorParameter sub tree?

Description:

my plugin has a welcome page and a dsp page, and I want to keep the selected page in the plugin state so I call `apvts.state.setProperty(“selectedPage”,”dsp”,nullptr)` or a`pvts.state.setProperty(“selectedPage”,”main”,nullptr)` whenever a page button is clicked.

To make the plugin respond to the click as well as showing the correct page when a preset is loaded, I have a `Value` object in the main component which itself is a `ValueTree::Listener`, listening to `apvts.state`. So whenever `valueTreeRedirected` is triggered I set `value.referTo(apvts.state.GetPropertyAsValue(“selectedPage”)`. The main component is also a `Value::Listener` so whenever “selectedPage” is changed during a session or loading a preset, the page is switched to the value stored in “selectedPage”. Wonderfull.

Every once in a while I get a `EXC_BAD_ACCESS` crash either in `ValueTree::SetProperty` regarding “selectedPage” property, or it might appear in `AudioProcessorValueTreeState:: flushParameterValuesToValueTree()`, referring me to some audio parameter I recently touched.

So obviously this is a threading violation. Should I take from this that I am not supposed to change `apvts.state` properties directly?

---

<div class="post-metadata">

**Author:** ![duvrin](https://avatars.discourse-cdn.com/v4/letter/d/a88e4f/32.png) [@duvrin](https://forum.juce.com/u/duvrin)\
**Post date:** [November 7, 2021, 1:54pm UTC](https://forum.juce.com/t/apvts-and-state-properties/48637/2 "2021-11-07T13:54:24Z")

</div>

This is me answering my own question:  
Why do you touch apvts.state property directly from a GUI class if you have a local Value object which is a reference to that property?  
Use `myValue="dsp"` instead of `apvts.state.setProperty(“selectedPage”,”dsp”,nullptr)`
