Hello - sorry, only just saw your post…
Yes, of course we can fix our demo code to avoid this particular race condition, but this isn’t a JUCE library bug, so us fixing the demo won’t magically fix your own app, or anyone else’s.
Obviously hosts like Tracktion will already have mechanisms to avoid clashes between plugin playback and state changes, but there’s nothing we can do in the library to enforce that behaviour.
Something we can do is to add an assertion if prepareToPlay gets called before setStateInformation returns, so that’ll at least stop other people falling down the same hole in the future.
But as for how you should deal with this in your own app, that’s up to you to decide based on what’s most appropriate in your case. Perhaps you should stop all playback during loading, or maybe you could start and stop individual plugins while you load their state… Depends entirely on what makes sense for you.