mirror of
https://github.com/yuzu-emu/yuzu-mainline.git
synced 2024-12-23 08:45:27 +00:00
Merge pull request #12151 from german77/no-crash
core: hid: Ensure output devices are initialized
This commit is contained in:
commit
bc4818b058
|
@ -509,9 +509,11 @@ void EmulatedController::ReloadInput() {
|
|||
});
|
||||
}
|
||||
turbo_button_state = 0;
|
||||
is_initalized = true;
|
||||
}
|
||||
|
||||
void EmulatedController::UnloadInput() {
|
||||
is_initalized = false;
|
||||
for (auto& button : button_devices) {
|
||||
button.reset();
|
||||
}
|
||||
|
@ -1207,6 +1209,9 @@ void EmulatedController::SetNfc(const Common::Input::CallbackStatus& callback) {
|
|||
}
|
||||
|
||||
bool EmulatedController::SetVibration(std::size_t device_index, VibrationValue vibration) {
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
if (device_index >= output_devices.size()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1242,6 +1247,10 @@ bool EmulatedController::IsVibrationEnabled(std::size_t device_index) {
|
|||
const auto player_index = Service::HID::NpadIdTypeToIndex(npad_id_type);
|
||||
const auto& player = Settings::values.players.GetValue()[player_index];
|
||||
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!player.vibration_enabled) {
|
||||
return false;
|
||||
}
|
||||
|
@ -1261,6 +1270,10 @@ Common::Input::DriverResult EmulatedController::SetPollingMode(
|
|||
EmulatedDeviceIndex device_index, Common::Input::PollingMode polling_mode) {
|
||||
LOG_INFO(Service_HID, "Set polling mode {}, device_index={}", polling_mode, device_index);
|
||||
|
||||
if (!is_initalized) {
|
||||
return Common::Input::DriverResult::InvalidHandle;
|
||||
}
|
||||
|
||||
auto& left_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Left)];
|
||||
auto& right_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
|
||||
auto& nfc_output_device = output_devices[3];
|
||||
|
@ -1306,6 +1319,10 @@ bool EmulatedController::SetCameraFormat(
|
|||
Core::IrSensor::ImageTransferProcessorFormat camera_format) {
|
||||
LOG_INFO(Service_HID, "Set camera format {}", camera_format);
|
||||
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& right_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
|
||||
auto& camera_output_device = output_devices[2];
|
||||
|
||||
|
@ -1329,6 +1346,11 @@ void EmulatedController::SetRingParam(Common::ParamPackage param) {
|
|||
}
|
||||
|
||||
bool EmulatedController::HasNfc() const {
|
||||
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto& nfc_output_device = output_devices[3];
|
||||
|
||||
switch (npad_type) {
|
||||
|
@ -1366,6 +1388,10 @@ bool EmulatedController::RemoveNfcHandle() {
|
|||
}
|
||||
|
||||
bool EmulatedController::StartNfcPolling() {
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& nfc_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
|
||||
auto& nfc_virtual_output_device = output_devices[3];
|
||||
|
||||
|
@ -1377,6 +1403,10 @@ bool EmulatedController::StartNfcPolling() {
|
|||
}
|
||||
|
||||
bool EmulatedController::StopNfcPolling() {
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& nfc_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
|
||||
auto& nfc_virtual_output_device = output_devices[3];
|
||||
|
||||
|
@ -1388,6 +1418,10 @@ bool EmulatedController::StopNfcPolling() {
|
|||
}
|
||||
|
||||
bool EmulatedController::ReadAmiiboData(std::vector<u8>& data) {
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& nfc_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
|
||||
auto& nfc_virtual_output_device = output_devices[3];
|
||||
|
||||
|
@ -1400,6 +1434,10 @@ bool EmulatedController::ReadAmiiboData(std::vector<u8>& data) {
|
|||
|
||||
bool EmulatedController::ReadMifareData(const Common::Input::MifareRequest& request,
|
||||
Common::Input::MifareRequest& out_data) {
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& nfc_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
|
||||
auto& nfc_virtual_output_device = output_devices[3];
|
||||
|
||||
|
@ -1412,6 +1450,10 @@ bool EmulatedController::ReadMifareData(const Common::Input::MifareRequest& requ
|
|||
}
|
||||
|
||||
bool EmulatedController::WriteMifareData(const Common::Input::MifareRequest& request) {
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& nfc_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
|
||||
auto& nfc_virtual_output_device = output_devices[3];
|
||||
|
||||
|
@ -1423,6 +1465,10 @@ bool EmulatedController::WriteMifareData(const Common::Input::MifareRequest& req
|
|||
}
|
||||
|
||||
bool EmulatedController::WriteNfc(const std::vector<u8>& data) {
|
||||
if (!is_initalized) {
|
||||
return false;
|
||||
}
|
||||
|
||||
auto& nfc_output_device = output_devices[static_cast<std::size_t>(DeviceIndex::Right)];
|
||||
auto& nfc_virtual_output_device = output_devices[3];
|
||||
|
||||
|
@ -1434,6 +1480,10 @@ bool EmulatedController::WriteNfc(const std::vector<u8>& data) {
|
|||
}
|
||||
|
||||
void EmulatedController::SetLedPattern() {
|
||||
if (!is_initalized) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (auto& device : output_devices) {
|
||||
if (!device) {
|
||||
continue;
|
||||
|
|
|
@ -559,6 +559,7 @@ private:
|
|||
NpadStyleTag supported_style_tag{NpadStyleSet::All};
|
||||
bool is_connected{false};
|
||||
bool is_configuring{false};
|
||||
bool is_initalized{false};
|
||||
bool system_buttons_enabled{true};
|
||||
f32 motion_sensitivity{Core::HID::MotionInput::IsAtRestStandard};
|
||||
u32 turbo_button_state{0};
|
||||
|
|
Loading…
Reference in a new issue