Fix crash on load: Add try/catch around findAllTypesForFile + createPluginInstance, use async path
Browse files1 unmodified line234556710 unmodified lines181920222122232 unmodified lines2627283132293031323334353637343536373839394040414242434445464748495051525346475548495051596061626364656667686970715253545556575859606162636465666768697071727374757677787374757677787980817980818283848586878889909175 unmodified lines1671681691631701711722 unmodified lines1751761771721781791801 unmodified line
HostedPluginManager::HostedPluginManager(){ // Register VST3 and AU formats explicitly (addDefaultFormats() removed in JUCE 8) #if JUCE_PLUGINHOST_VST3 formatManager.addFormat(new juce::VST3PluginFormat()); #endif10 unmodified linesvoid HostedPluginManager::loadPlugin(const juce::File& pluginFile, double sampleRate, int blockSize){ // Unload existing plugin first unloadPlugin();
currentSampleRate = sampleRate;2 unmodified lines juce::String errorMessage; juce::OwnedArray<juce::PluginDescription> typesFound;
// Scan the file to find plugin descriptions for (int i = 0; i < formatManager.getNumFormats(); ++i) // Wrap in try/catch — some plugins throw or show dialogs that cause exceptions try { for (int i = 0; i < formatManager.getNumFormats(); ++i) { auto* format = formatManager.getFormat(i); format->findAllTypesForFile(typesFound, pluginFile.getFullPathName()); if (typesFound.size() > 0) break; auto* format = formatManager.getFormat(i); format->findAllTypesForFile(typesFound, pluginFile.getFullPathName()); if (typesFound.size() > 0) break; } }
if (typesFound.isEmpty()) catch (...) { DBG("PluginBridge: No plugin found in file: " + pluginFile.getFullPathName()); DBG("PluginBridge: Exception during plugin scan for: " + pluginFile.getFullPathName()); return; }
// Use the first plugin description found auto& desc = *typesFound[0];
// Create plugin instance (synchronous — safe here since we're on message thread) auto instance = formatManager.createPluginInstance( desc, sampleRate, blockSize, errorMessage);
if (instance == nullptr) if (typesFound.isEmpty()) { DBG("PluginBridge: Failed to create plugin: " + errorMessage); DBG("PluginBridge: No plugin found in file: " + pluginFile.getFullPathName()); return; }
// Enable all buses before use instance->enableAllBuses();
// Match bus layout: stereo in/out auto layout = juce::AudioProcessor::BusesLayout(); layout.inputBuses.add(juce::AudioChannelSet::stereo()); layout.outputBuses.add(juce::AudioChannelSet::stereo());
if (instance->checkBusesLayoutSupported(layout)) instance->setBusesLayout(layout);
// Prepare for playback instance->prepareToPlay(sampleRate, blockSize); auto desc = *typesFound[0];
// Use async creation — safer for AU plugins and plugins that need message thread formatManager.createPluginInstanceAsync(desc, sampleRate, blockSize, [this, pluginFile](std::unique_ptr<juce::AudioPluginInstance> instance, const juce::String& error) { if (instance == nullptr) { DBG("PluginBridge: Failed to create plugin: " + error); return; }
// Enable all buses instance->enableAllBuses();
// Match bus layout: stereo in/out auto layout = juce::AudioProcessor::BusesLayout(); layout.inputBuses.add(juce::AudioChannelSet::stereo()); layout.outputBuses.add(juce::AudioChannelSet::stereo());
if (instance->checkBusesLayoutSupported(layout)) instance->setBusesLayout(layout);
// Prepare for playback instance->prepareToPlay(currentSampleRate, currentBlockSize);
// Store { const juce::ScopedLock sl(pluginLock); hostedPlugin = std::move(instance); loadedPluginPath = pluginFile.getFullPathName(); }
DBG("PluginBridge: Loaded plugin: " + getPluginName() + " (" + juce::String(getParameterCount()) + " params)"); // Store { const juce::ScopedLock sl(pluginLock); hostedPlugin = std::move(instance); loadedPluginPath = pluginFile.getFullPathName(); }
DBG("PluginBridge: Loaded plugin: " + getPluginName() + " (" + juce::String(getParameterCount()) + " params)"); });}
void HostedPluginManager::unloadPlugin()75 unmodified lines info.displayText = param->getText(param->getValue(), 64); info.automatable = param->isAutomatable();
// Try to get stable ID from HostedParameter if (auto* hosted = dynamic_cast<juce::AudioPluginInstance::HostedParameter*>(param)) info.id = hosted->getParameterID(); else2 unmodified lines results.push_back(info); }
// Cap results to avoid token bloat if (results.size() >= 20) break; }Source/HostedPluginManager.cpp+49-44