getNumDrivers returns "NoDevice" after re-plugging last device

Hi,

I’m working on hot swapping Audio output devices. Everything wokrs nice and smoothly until i re-plug the last remaining device in the system. When it’s remove i get this error:

[FMOD] OutputWASAPI::mixerThread : GetCurrentPadding returned 0x88890004.  Device was unplugged!

After pluging it back, the DEVICE LIST CHANGED callback kicks in, but iterating through list of devices shows only one entry and it’s “no device” . Fmod never recovers and i can;t hear audio at all.

Same thing happens when i start the game with all devices unplugged.

Hi,

Thanks for bringing this to our attention. What version of the FMOD integration are you using? Please could I get the code you are using to detect the output devices?

FMOD integration Version: 2.01.19

This is the code i use for the callback:

List<string> GetOutputDevices()
{
    List<string> devices = new();
    RuntimeManager.CoreSystem.getNumDrivers(out var drivers);

    for (int i = 0; i < drivers; i++)
    {
        RuntimeManager.CoreSystem.getDriverInfo(i, out var name, 120, out Guid g, out int sample, out var speakerMode, out int a);
        Debug.Log($"{i}: {name}");
        if (g == Guid.Empty)
            continue;
        devices.Add(name);
    }

    return devices;
}


[AOT.MonoPInvokeCallback(typeof(FMOD.SYSTEM_CALLBACK))]
static FMOD.RESULT DeviceChangedCallback(IntPtr system, FMOD.SYSTEM_CALLBACK_TYPE type, IntPtr commanddata1, IntPtr commanddata2, IntPtr userdata)
{
    Debug.Log("output device list changed");
    foreach (var instance in instances)
    {

        if (instance.GetOutputDevices().Count > 0)
            instance.Setting.SetChoices(instance.GetOutputDevices());
        else
            instance.Setting.SetChoices(new List<string>());
    }
    return FMOD.RESULT.OK;
}

Thank you for the script.

Unfortunately, 2.01 is no longer supported. Can I confirm your integration version:
image
image

We have documentation for migrating major versions for Studio here: FMOD Studio | Advanced Topics - Migration FMOD Studio Projects.
Migrating Unity versions will be aided by the Unity Integration | Tools - Event Reference Updater.

A few improvements to the device list changed callback since 2.01 may solve the issue.