JUCE icon indicating copy to clipboard operation
JUCE copied to clipboard

[Bug]: Exception in `getNextAudioBlock` or `handleIncomingMidiMessage` silently causes app to stop working

Open dziemba opened this issue 1 year ago • 0 comments
trafficstars

Detailed steps on how to reproduce the bug

Create a standalone app, which has a MidiInputCallback implemented:

void MainComponent::handleIncomingMidiMessage(juce::MidiInput *source, const juce::MidiMessage &message) {
  std::cout << "MIDI received" << std::endl;
  throw std::exception();
}

If the handler receives a MIDI message and throws, the program keeps running as if nothing happend. But after the handler has thrown once, it will not be called ever again with any later MIDI messages.

Similar behavior occurs when throwing in getNextAudioBlock:

void MainComponent::getNextAudioBlock(const juce::AudioSourceChannelInfo &bufferToFill) {
  [ ... regular audio code ... ]  
  static int i = 0;
  if (i++ == 1000) {
    throw std::exception();
  }
}

Once the 1000th buffer has been reached, audio will stop and not resume.

What is the expected behaviour?

Silently breaking the program is unexpected to me. I would expect the program to either abort fatally (which happens e.g. if you throw in the paint method), or catch the exceptions and do a jassertfalse. If catching exceptions is a performance issue, this could be only done if JUCE_DEBUG is enabled.

With the current behavior you will only notice that something went wrong if you have a debugger attached. Without a debugger, the program will continue as usual but the MIDI input will stop working.

For the audio handler the issue will be obvious immediately (since audio stops) but for the MIDI handler it's a bit more subtle to understand what happened (especially if the exceptions get thrown very rarely due to some corner case).

Operating systems

macOS

What versions of the operating systems?

macOS 14.5 (23F79)

Architectures

ARM

Stacktrace

No response

Plug-in formats (if applicable)

Standalone

Plug-in host applications (DAWs) (if applicable)

No response

Testing on the develop branch

The bug is present on the develop branch

Code of Conduct

  • [X] I agree to follow the Code of Conduct

dziemba avatar Aug 03 '24 13:08 dziemba