Skip to content

ASIO: collecting output_devices() into Vec only returns the first device #1106

@mikai233

Description

@mikai233

Summary

On Windows ASIO, host.output_devices() behaves differently depending on whether the iterator is collected first.

  • Iterating directly prints all devices.
  • Collecting into Vec<_> first, then iterating, only prints the first device.

collect should not change the visible device set.

Environment

  • cpal: 0.17.1
  • OS: Windows (x64)
  • Backend: ASIO (cpal::HostId::Asio)
  • Devices in my setup:
    • Focusrite USB ASIO
    • Realtek ASIO
    • USB DAC ASIO

Minimal Repro

use anyhow::Result;
use cpal::traits::{DeviceTrait, HostTrait};

fn list_output_devices() -> Result<()> {
    let host = cpal::host_from_id(cpal::HostId::Asio)?;
    let devices = host.output_devices()?;
    // let devices = devices.collect::<Vec<_>>();
    for device in devices {
        println!("{}", device.description()?);
    }
    Ok(())
}

fn main() -> Result<()> {
    list_output_devices()
}

Actual Behavior

Without collect:

Focusrite USB ASIO
Realtek ASIO
USB DAC ASIO

With:

let devices = devices.collect::<Vec<_>>();

Only the first device is printed:

Focusrite USB ASIO

Expected Behavior

Both versions should enumerate the same set of devices (all 3 in this environment).

Related

Possibly related to ASIO enumeration/lifetime behavior in #798 (this repro is single-threaded and triggered by collecting Device values).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions