@@ -1083,13 +1083,12 @@ fn preferred_host() -> Result<Host, AudioError> {
10831083
10841084fn enumerate_output_devices ( host : & Host ) -> Result < Vec < ( Device , AudioDeviceInfo ) > , AudioError > {
10851085 let mut output_devices = Vec :: new ( ) ;
1086- for device in host. devices ( ) ? {
1086+ for ( host_index , device) in host. devices ( ) ?. enumerate ( ) {
10871087 if let Ok ( config) = device. default_output_config ( ) {
1088- let index = output_devices. len ( ) ;
10891088 output_devices. push ( (
10901089 device. clone ( ) ,
10911090 AudioDeviceInfo {
1092- index,
1091+ index : host_index ,
10931092 name : device. name ( ) ?,
10941093 is_input : false ,
10951094 channels : config. channels ( ) ,
@@ -1103,13 +1102,12 @@ fn enumerate_output_devices(host: &Host) -> Result<Vec<(Device, AudioDeviceInfo)
11031102
11041103fn enumerate_input_devices ( host : & Host ) -> Result < Vec < ( Device , AudioDeviceInfo ) > , AudioError > {
11051104 let mut input_devices = Vec :: new ( ) ;
1106- for device in host. devices ( ) ? {
1105+ for ( host_index , device) in host. devices ( ) ?. enumerate ( ) {
11071106 if let Ok ( config) = device. default_input_config ( ) {
1108- let index = input_devices. len ( ) ;
11091107 input_devices. push ( (
11101108 device. clone ( ) ,
11111109 AudioDeviceInfo {
1112- index,
1110+ index : host_index ,
11131111 name : device. name ( ) ?,
11141112 is_input : true ,
11151113 channels : config. channels ( ) ,
@@ -1141,6 +1139,10 @@ fn select_device(
11411139 if let Some ( ( device, _) ) = entries. iter ( ) . find ( |( _, info) | info. index == index) {
11421140 return Ok ( device. clone ( ) ) ;
11431141 }
1142+ // Backward-compat fallback for previously persisted compact indices.
1143+ if let Some ( ( device, _) ) = entries. get ( index) {
1144+ return Ok ( device. clone ( ) ) ;
1145+ }
11441146 }
11451147 if is_input {
11461148 if let Some ( default_device) = host. default_input_device ( ) {
0 commit comments