[bug report] Initialise AudioDeviceManager return empty String when there's no available devices

Initialise AudioDeviceManager return empty result String when there’s no available audio device.
But it was failed actually. (No way it should succeed in this situation)
But the document said:

an error message if anything went wrong, or an empty string if it worked ok.

returning an empty String should mean that the initialisation have succeeded, but in this case it’s not.
So I think this might be a JUCE bug.

The link of the same issue reported on github: https://github.com/WeAreROLI/JUCE/issues/462

Thanks Jerry - we’ll have a look at this today!

Thanks Jules!

Can you post some example code which reproduces this? If I run the AudioSettingsDemo and change line 67 to:

auto err = audioDeviceManager.initialise (numInputChannels, 2, nullptr, true, {}, nullptr);

jassert (err.isNotEmpty());
DBG (err);

and disable all of the audio devices via the Windows sound preferences then I get the following error message:

Can’t open the audio device!

This may be because another application is currently using the same device - if so, you should close any other applications and try again!

Hi ed!
Sorry to have kept you waiting for so long, I am busy today, just have time to review this issue.

I just wrote a minimal reproduction code like this:

AudioDeviceManager audioDeviceManager;
AudioDeviceManager::AudioDeviceSetup deviceSetup;

deviceSetup.bufferSize = 512;
deviceSetup.sampleRate = 44100.0;

String resultString = audioDeviceManager.initialise(1, 2, nullptr, true, String(), &deviceSetup);
AudioIODevice *currentDevice = audioDeviceManager.getCurrentAudioDevice();

if (resultString.isEmpty() && currentDevice == nullptr) jassertfalse;

And if I close my usb sound card, and disable all the build-in audio device in the Windows sound preference, then I’ll hit this assertion.

Hope these will be helpful to you!

I still get the same error message as above when I run that code with the input and output devices disabled in the Windows sound preferences.

Can you try stepping through in the debugger and see what the values of outputIndex and inputIndex are at this line? They should both be 0 if no devices have been found. Also, I’m assuming that you are using the default juce_audio_devices settings and that you’re using WASAPI and not ASIO but please let me know if you have a different setting.

Hi ed,
I did some testing on different environments, and found that, in JUCE 5.4.1 release (is what we’re using in our project), this bug exits, and I can’t hit the breakpoint of the line you said.
But in current develop brunch, I do get the error message you said, but the “outputIndex” and “inputIndex” are in value of “-1”.

Functionally, this bug seems to have been fixed on the develop branch, but I don’t know if this “-1” is something that you don’t expect to see.
Anyway, we have workaround manually in our project (which is using JUCE 5.4.1) by checking whether the “currentDevice” is nullptr.
And because we want our project to be stable, and don’t need to update JUCE’s module code everyday, so we choose to use only the code in master brunch.
So, looking forward for your future release!

Sorry I meant -1, that all looks correct. There have been a number of improvements to the AudioDeviceManager and its associated classes since 5.4.1 which will make their way into the next stable release.

As the develop branch moves quite quickly it’s always worth checking bugs against it before posting on the forum as they may have already been fixed.