Again, prepareToPlay() is called twice, but releaseResources() is not called inbetween. Since I’m loading a lib in prepareToPlay() that’s only allowed to be instantiated once, I’m running into trouble here.
Furthermore, when the plugin is deleted from the filter graph, I’m running into a second problem. Here, releaseResources() is also called twice. Which means that my already released memory is released again.
Can somebody tell my, why the hosts need to call the functions twice? What would be a proper way to implement the memory management here?
Can every host call the functions in an arbitrary order? Or is there some kind of standardization?
And the same applies to releaseResources(), I assume? I hoped this would be better (ore more standardized) with VST3…
Yes, this is really annoying. In AudioMulch the blocksize varies from time to time in processBlock(), especially if the buffer size set in the sound card is not a multiple of 64. It took me quite some time to solve this problem, since we’re working with filterbanks that require a fixed block size.
prepareToPlay serves two purposes, that often go hand in hand:
report the rendering parameters
give the chance to allocate resources
It makes sense to use that together, because allocating resources often depends on the parameters, e.g. the size of a delay line depends on the sample rate.
Whenever the routing of a plugin changes, many hosts will call prepareToPlay, because the parameters might have changed. In case of the AudioSource you can observe, that the ones that have an input source will forward the call to the input source to be safe.
releaseResource() is not often used, because nowadays you should use RAII methods to manage your memory, and the resources are usually held until the plugin is destroyed anyway.
TL;DR: don’t think of the pair as prepareToPlay as a place to new raw pointers (you shouldn’t do that anyway) and releaseResources() to delete. Those calls have no place in modern projects.
But rather to setup your coefficients and AudioBuffer sizes, set the latency and similar things.
Memory management is not meant to be implemented here.