Problem with copyState() on APVTS object

I’m working on a preset saving/loading system and I need to create an xml from the APVTS state which holds all the parameters, but trying to access the state always throws an error with the line:
auto currentState = tree.copyState();
Specifically, the debugger points me to an issue on line 397 of the “juce_AudioProcessorValueTreeState.cpp” file:
ScopedLock lock (valueTreeChanging);
Does anyone have any clues as to what might cause this?

It would help if you gave some kind of clue as to what the error was.

Are you calling it from audio processing code, perhaps? The copyState() function says it is thread-safe, but not real-time safe.

1 Like

Specifically, it’s a function of the AudioProcessor subclass. I put it in there for immediate access to the processor’s APVTS, but I’ll try separating it out since it sounds like handling it in audio processing might be the issue.

It’s ok to have in that class, just make sure it’s not being called from the audio thread (such as from processBlock()). It’s often called from (for example) getStateInformation(), to store the current state into the session data.