AudioPluginInstance is nullptr when running as a plugin, but works just fine when running as standalone

Greetings.

In my plugin, I want to host a nested plugin.
When I run the plugin in a host DAW (I’ve tested with Ableton Live and REAPER), the AudioPluginInstance is always nullptr.
However, when I run my plugin as standalone, everything works just fine.

this is what my prepareToPlay() looks like:

if (prepared)
    return;

prepared = true;

juce::String pluginPath = "C:\\Program Files\\Common Files\\VST3\\OTT.vst3";
OwnedArray<PluginDescription> pluginDescriptions;
KnownPluginList plist;
pluginFormatManager.addDefaultFormats();
juce::String msg;

for (int i = 0; i < pluginFormatManager.getNumFormats(); ++i)
    plist.scanAndAddFile(pluginPath, true, pluginDescriptions,
                         *pluginFormatManager.getFormat(i));

jassert(pluginDescriptions.size() > 0);
plugin = pluginFormatManager.createPluginInstance(*pluginDescriptions[0],
                                                    sampleRate, samplesPerBlock, msg);

plugin is of type std::unique_ptr<juce::AudioPluginInstance>,
and msg is always empty.

Help is very much appreciated.

I can’t think of anything obvious, so these are just guesses:

  • Are you sure that prepareToPlay is always being called?
  • A bit of a stretch, but assuming that your copy of OTT is 64-bit, are you testing with a 32-bit build of your plugin, instead of 64-bit?

Thank you for your reply

Yes, I am sure that prepareToPlay is being called
I am testing with a 64 bit build of my plugin

Fixed it!

prepareToPlay can get called multiple times from a host, which is why I have this code at the start of prepareToPlay:

if (prepared) 
    return;

prepared = true;

// rest of the code to prepareToPlay()

Some of my plugin’s data gets allocated in prepareToPlay, and by having that function called multiple times, it interferes with the functionality of my plugin.

If I remove the code checking if prepareToPlay has been called before, the sub-plugin gets created and works as expected.