Skip to content

Commit

Permalink
Prevent ArrayIndexOutOfBoundsException when none of the devices have …
Browse files Browse the repository at this point in the history
…any inputs
  • Loading branch information
kevinstadler committed Sep 20, 2023
1 parent 3306f82 commit 4c8d287
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/processing/sound/Engine.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ private void createSynth(AudioDeviceManager deviceManager) {
if (this.synth != null) {
this.stopSynth(true);
}
// this might be -1 if there is no device with inputs. handled below.
this.inputDevice = deviceManager.getDefaultInputDeviceID();
this.outputDevice = deviceManager.getDefaultOutputDeviceID();
this.synth = JSyn.createSynthesizer(deviceManager);
Expand Down Expand Up @@ -191,6 +192,9 @@ private void startSynth() {
}
this.setVolume(1.0f);

// prevent IndexOutOfBoundsException on input-less devices
int inputChannels = this.inputDevice >= 0 ?
this.synth.getAudioDeviceManager().getMaxInputChannels(this.inputDevice) : 0;
this.synth.start(this.sampleRate,
this.inputDevice, this.synth.getAudioDeviceManager().getMaxInputChannels(this.inputDevice),
this.outputDevice, this.synth.getAudioDeviceManager().getMaxOutputChannels(this.outputDevice));
Expand Down

0 comments on commit 4c8d287

Please sign in to comment.