Problems with device initialisation

Hi,
I’m trying to load last used device settings via xml created by AudioDeviceManager::createStateXml().

First version of my code looked like this:

std::unique_ptr<juce::XmlElement> xml = juce::XmlDocument(juce::File::getSpecialLocation(juce::File::userDocumentsDirectory).getChildFile("AATMuSS Presets").getChildFile("last_device.xml")).getDocumentElement();
deviceManager.initialise(MAX_NUM_INPUTS, MAX_NUM_OUTPUTS, xml.get(), true);

It works fine when the xml is empty, when the specified device doesn’t have drivers installed (it falls back to default settings) or when the drivers are present and the device itself is plugged in. However, when the driver is valid but the device is unplugged, deviceManager.getCurrentAudioDevice() returns nullptr, which leads me to believe the initialisation was unsuccessful. The problem is that the 4th argument of initialise() being ‘true’ should revert to default device settings when it fails… but it doesn’t.

Alrighty, I thought, I guess I have to do it myself. So I added this check:

if (deviceManager.getCurrentAudioDevice() == nullptr)
{
    deviceManager.initialiseWithDefaultDevices(MAX_NUM_INPUTS, MAX_NUM_OUTPUTS);
}

The condition does indeed pass, but initialiseWithDefaultDevices() does nothing. Even after this, getCurrentAudioDevice() still returns nullptr.

Considering I’m a noob, I’m guessing I’m doing something wrong, but I just can’t figure out what. Can anyone help?