Plugin restoring and saving

I have a VST audio plugin that displays a single audio file on an AudioThumbnail and plays it. I have a slim rectangle being drawn over the thumbnail to indicate my transport source’s play head position.
If I debug the plugin with the VST debugger, I can load an audio file, play and visualize it successfully.

The problem is that if I close the plugin and re-open it, I get this access violation: Exception thrown at 0x0000000000000000 in AudioPluginHost.exe: 0xC0000005: Access violation executing location 0x0000000000000000. This happens because the thumbnail’s cursor position is updated on a timer callback, and the setRectangle function that updates the marker calls the transport source’s getCurrentPosition() method. The call stack ends on the following assertion in BufferingAudioSource::getNextReadPosition(): jassert (source->getTotalLength() > 0);

What is going on when the plugin is being closed / restored?

I have just found out about get/setStateInformation, which I will implement hoping to solve this problem. Will I need to store audio source and thumbnail objects here?

From what I can see, when you close and re-open your plug-in, your audio file is no longer there.

A key thing to understand is that the thumbnail is not the data itself. It’s only a graphical representation of the data.

When you close the plug-in, the data (the audio file) should still be loaded in the audio buffer (or wherever you’ve put your audio file data). If it disappears when you close the UI, that sounds like you’ve somehow stored the audio data in your editor, which is destroyed when you close the UI. All your underlying data should be handled on the processor side of the plug-in. That ensures that even when the UI is closed, you can still use the plug-in because all the underlying data is still there.

Saving and loading your state is from XML, which is essentially a text file that gives a “snapshot” of what your settings were when you saved your state. It doesn’t save your thumbnail or audio source itself. If you’re seeking to load the last file you were using before you closed it, I’d imagine you’d want to save the directory location of the file and load from there, or maybe copy the file to a “samples” folder then load from there.

Hope that helps!

Thanks for that Joshua, definitely helped. I had to move quite a bit of things that should’ve been part of the processor, and now the editor can be reconstructed as it should.

So what will I miss out on if I don’t implement get/setStateInformation? If I had to guess, it would be preset saving/loading.

The main thing you’d miss out on is that your plug-in / app wouldn’t be able to save a current state, so if your user is working in a project and they save their work, when they re-open the project your plug-in will just open with its initial settings.