AudioProcessorValueTreeState not restoring

I am not sure what I am doing wrong. I’ve followed all the tutorials and yet, when I reload my plugin, the state values are not restored.

In my editor, I am using these which I am calling at the end or resize.

valueTreeState.state.setProperty(“width”, ( float )getWidth(), nullptr );
valueTreeState.state.setProperty(“height”, ( float )getHeight(), nullptr );

To store the current width and height to the valueState Tree. In my constructor for the editor, I am using:

setSize(( int )*audioProcessor.e_width,( int )*audioProcessor.e_height);

Which I set e_width and e_height using a raw pointer.

If I close and open the editor, I see the size come back up properly.

However, if I close my host (Live) and reopen the saved .ALS file, the size is now the detault coded when I created the parameters:

std::make_unique<juce::AudioParameterFloat>(“width”, “Width”, 175, 2048, 1024),
std::make_uniquejuce::AudioParameterFloat>(“height”, “Height”, 75, 2048, 256),

The getStateInformation and setStateInformation are EXACTLY from the tutorial.

I’m sure I am doing something wrong, I just cannot figure out what it is. Any pointers of where to look?

why don’t you use the valueTree in your editor’s constructor directly to get the current values of width and height, rather than pre-saving them in the processor? i’m also a little confused why you use audio parameters for that. you can just directly save and load properties or children on that valueTree and it will automatically serialize along side your parameters in getState and setState

I plan on switching to saving them in the value tree directly as I’ve seen in other examples on the forum, as that does make the most sense. I’m just unclear why what I did here doesn’t work. I guess I can add some code to getState and setState to see what is happening in those calls.

Weird, so I created a string in my processor and append to it every time get or set state is called. When I start up my Live project, I get one call to getState. Why it would call getState instead of setState is beyond me.

Okay, just found this thread and it looks like the same issue, I need to handle the get before set that is happening.

This has sent me down an entire rabbit hole, and while I have been getting closer, I am still not there.

In my constructor for my processor, I am adding:

state.state.addChild ({ “uiState”, { { “width”, 1024 }, { “height”, 256 }}, {} }, -1, nullptr );

This way I can pull these from the state (and put them in)

The examples I saw use juce::Value and referTo to point to those values. I tried following other examples and I guess I am just not sure why I keep getting crashes. My assumption is that given Value are not thread safe, I wonder if I am hitting that sort of issue.

I put the juce::Value members variables in the processor, so they always exist. When I do a setState, I redo the refTo since from what I can see, we are replacing the state, so we need to reset the reference.

This all works, unless I want to set these values from the Editor. If I do something like this in the resized callback

audioProcessor.lastWidth = GetWidth();

This crashes the second time the UI is up. The crash lists a bunch of stuff about Listeners.

So, open Live, Open UI on plugin, change the size, close UI, openUI on plugin, start to drag again the size and crash.

I also have a value tree listener setup that when the value tree changes, it calls setSize, but this is not where it is crashing.

Not sure what to do next.

Okay, finally got it working correctly. For anyone that hits this, using the method in this thread worked the best!