diff --git a/alvr/server_core/src/connection.rs b/alvr/server_core/src/connection.rs index 606b42b8a4..50da6ce415 100644 --- a/alvr/server_core/src/connection.rs +++ b/alvr/server_core/src/connection.rs @@ -1074,25 +1074,24 @@ fn connection_pipeline( let control_receive_thread = thread::spawn({ let ctx = Arc::clone(&ctx); - let mut controller_button_mapping_manager = server_data_lock - .settings() - .headset - .controllers - .as_option() - .map(|config| { - if let Some(mappings) = &config.button_mappings { - ButtonMappingManager::new_manual(mappings) - } else { - ButtonMappingManager::new_automatic( - &CONTROLLER_PROFILE_INFO - .get(&alvr_common::hash_string(QUEST_CONTROLLER_PROFILE_PATH)) - .unwrap() - .button_set, - &config.emulation_mode, - &config.button_mapping_config, - ) - } - }); + + let controllers_config = server_data_lock.settings().headset.controllers.as_option(); + let mut controller_button_mapping_manager = controllers_config.map(|config| { + if let Some(mappings) = &config.button_mappings { + ButtonMappingManager::new_manual(mappings) + } else { + ButtonMappingManager::new_automatic( + &CONTROLLER_PROFILE_INFO + .get(&alvr_common::hash_string(QUEST_CONTROLLER_PROFILE_PATH)) + .unwrap() + .button_set, + &config.emulation_mode, + &config.button_mapping_config, + ) + } + }); + let controllers_emulation_mode = + controllers_config.map(|config| config.emulation_mode.clone()); let disconnect_notif = Arc::clone(&disconnect_notif); let control_sender = Arc::clone(&control_sender); @@ -1231,23 +1230,27 @@ fn connection_pipeline( }; } ClientControlPacket::ActiveInteractionProfile { profile_id, .. } => { - controller_button_mapping_manager = - if let (Switch::Enabled(config), Some(profile_info)) = ( - &SERVER_DATA_MANAGER.read().settings().headset.controllers, - CONTROLLER_PROFILE_INFO.get(&profile_id), - ) { - if let Some(mappings) = &config.button_mappings { - Some(ButtonMappingManager::new_manual(mappings)) - } else { - Some(ButtonMappingManager::new_automatic( - &profile_info.button_set, - &config.emulation_mode, - &config.button_mapping_config, - )) - } + controller_button_mapping_manager = if let ( + Switch::Enabled(config), + Some(profile_info), + Some(emulation_mode), + ) = ( + &SERVER_DATA_MANAGER.read().settings().headset.controllers, + CONTROLLER_PROFILE_INFO.get(&profile_id), + &controllers_emulation_mode, + ) { + if let Some(mappings) = &config.button_mappings { + Some(ButtonMappingManager::new_manual(mappings)) } else { - None - }; + Some(ButtonMappingManager::new_automatic( + &profile_info.button_set, + emulation_mode, + &config.button_mapping_config, + )) + } + } else { + None + }; } ClientControlPacket::Log { level, message } => { info!("Client {client_hostname}: [{level:?}] {message}") @@ -1275,11 +1278,13 @@ fn connection_pipeline( if let Some(mappings) = &config.button_mappings { Some(ButtonMappingManager::new_manual(mappings)) } else { - Some(ButtonMappingManager::new_automatic( - &input_ids, - &config.emulation_mode, - &config.button_mapping_config, - )) + controllers_emulation_mode.as_ref().map(|emulation_mode| { + ButtonMappingManager::new_automatic( + &input_ids, + emulation_mode, + &config.button_mapping_config, + ) + }) } } else { None