From 3c1012baebef97410461c7e2597652b0102d782c Mon Sep 17 00:00:00 2001 From: reuk Date: Thu, 8 May 2025 14:15:34 +0100 Subject: [PATCH] AudioDeviceManager: Handle loading of XML with missing fields more gracefully --- .../audio_io/juce_AudioDeviceManager.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp b/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp index bd558f2eb4..8abf686460 100644 --- a/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp +++ b/modules/juce_audio_devices/audio_io/juce_AudioDeviceManager.cpp @@ -511,6 +511,16 @@ String AudioDeviceManager::initialiseFromXML (const XmlElement& xml, currentDeviceType = firstType->getTypeName(); } + const auto deviceNameMissing = (numInputChansNeeded > 0 && setup.inputDeviceName .isEmpty()) + || (numOutputChansNeeded > 0 && setup.outputDeviceName.isEmpty()); + + // If there's no device name, then normally this would prevent a device from opening. + // If failing to open a device would conflict with the number of requested channels, then we + // pre-emptively treat this as a failure and fall back to using devices that're able to provide + // the requested channel counts. + if (selectDefaultDeviceOnFailure && deviceNameMissing) + insertDefaultDeviceNames (setup); + setup.bufferSize = xml.getIntAttribute ("audioDeviceBufferSize", setup.bufferSize); setup.sampleRate = xml.getDoubleAttribute ("audioDeviceRate", setup.sampleRate);