juce_win32_ASIO.cpp removeCurrentDriver() crashes if ASIO device is not available

Whenever no ASIO compatible devices are connected but an attempt is made to select one (using an AudioDeviceSelectorComponent), an exception occurs in juce_win32_ASIO.cpp at line 1080 (asioObject->Release();):

void removeCurrentDriver()
    if (asioObject != nullptr)
        asioObject = nullptr;

Ausnahme ausgelöst bei 0x00007FF96BA9FE8A (ntdll.dll) in RealtimeSpectrogams.exe: 0xC0000008: An invalid handle was specified.

Since IASIO* asioObject is a private member ASIOAudioIODevice, I assume that something is not working properly in this class. Seems that asioObject is not null but does not point to an IASIO instance.

Is this happening with a specific ASIO device? If I try to select for example a “Focusrite USB ASIO” device via the AudioDeviceSelectorComponent and I don’t have a compatible device connected then the asioDevice object is created in tryCreatingDriver() but initDriver() fails in openDevice() and removeCurrentDriver() works as expected.

It is happening with both ASIO devices I tried: Steinberg UR 12 and RME Fireface UFX.
I should mention that audio I/O was running in the background while my AudioDeviceSelectorComponent was opened in a dialog. In case of Windows Audio and DirectSound, audio I/O stops for maybe a few 100ms then starts again. ASIO => crash, at least in debug mode.

It seems that this is happening inside the ASIO object of the driver, I can’t see anything that we’re doing wrong in JUCE. I’ve pushed a workaround to the develop branch here that won’t release the object for the Steinberg driver. I couldn’t get hold of the RME driver to test with though, if it’s the same crash then let me know the name of the driver and I’ll add it to the list.