Cycling74 / rnbo.example.juce

Template project for creating RNBO and JUCE based Desktop applications and/or Audio Plugins
62 stars 9 forks source link

Crash on certain hosts due to initial preset value being set to -1 #18

Closed yamadapc closed 1 year ago

yamadapc commented 1 year ago

This is fine on most iOS hosts, but for AUM (https://apps.apple.com/us/app/aum-audio-mixer/id1055636344) which is a highly used host for iOS, the fact the initial program is set to -1 causes the plugin to crash.

The reason is that -1 is not a valid program index and JUCE AudioUnit code is not handling -1 as an input. See:

What AUM seems to do it:

AUAudioUnitPreset* getAtIndex (int index) const
{
     std::lock_guard<std::mutex> lock (mutex);

     if (index < (int) [presets.get() count])
          return [presets.get() objectAtIndex: (unsigned int) index];

     return nullptr;
}

The fix could be to for RNBO::JuceAudioProcessor's _currentPresetIdx field to be initialised to 0 or a different value. I can verify setting the program to 0 (as well as patching JUCE bounds checking code above to consider lower bounds) fixes crashes in AUM for my iOS plugin.

All the best

yamadapc commented 1 year ago

The problem is on RNBO_JuceAudioProcessors.cpp line 246:

    , _currentPresetIdx(-1)
yamadapc commented 1 year ago

Closing this in favour of https://github.com/Cycling74/rnbo.adapter.juce/issues/5