mirror of
https://github.com/wiiu-env/EnvironmentLoader.git
synced 2025-01-13 13:39:12 +01:00
Limit the number of VPADRead attempts to avoid potential softlocks
This commit is contained in:
parent
be78693cb7
commit
4d9e4f73c9
@ -1,5 +1,4 @@
|
|||||||
#include "InputUtils.h"
|
#include "InputUtils.h"
|
||||||
#include "logger.h"
|
|
||||||
#include <coreinit/thread.h>
|
#include <coreinit/thread.h>
|
||||||
#include <padscore/kpad.h>
|
#include <padscore/kpad.h>
|
||||||
#include <padscore/wpad.h>
|
#include <padscore/wpad.h>
|
||||||
@ -96,9 +95,10 @@ uint32_t remapClassicButtons(uint32_t buttons) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
InputUtils::InputData InputUtils::getControllerInput() {
|
InputUtils::InputData InputUtils::getControllerInput() {
|
||||||
InputData inputData{};
|
InputData inputData = {};
|
||||||
VPADStatus vpadStatus{};
|
VPADStatus vpadStatus = {};
|
||||||
VPADReadError vpadError = VPAD_READ_UNINITIALIZED;
|
VPADReadError vpadError = VPAD_READ_UNINITIALIZED;
|
||||||
|
int maxAttempts = 100;
|
||||||
do {
|
do {
|
||||||
if (VPADRead(VPAD_CHAN_0, &vpadStatus, 1, &vpadError) > 0 && vpadError == VPAD_READ_SUCCESS) {
|
if (VPADRead(VPAD_CHAN_0, &vpadStatus, 1, &vpadError) > 0 && vpadError == VPAD_READ_SUCCESS) {
|
||||||
inputData.trigger = vpadStatus.trigger;
|
inputData.trigger = vpadStatus.trigger;
|
||||||
@ -107,10 +107,10 @@ InputUtils::InputData InputUtils::getControllerInput() {
|
|||||||
} else {
|
} else {
|
||||||
OSSleepTicks(OSMillisecondsToTicks(1));
|
OSSleepTicks(OSMillisecondsToTicks(1));
|
||||||
}
|
}
|
||||||
} while (vpadError == VPAD_READ_NO_SAMPLES);
|
} while (--maxAttempts > 0 && vpadError == VPAD_READ_NO_SAMPLES);
|
||||||
|
|
||||||
KPADStatus kpadStatus{};
|
KPADStatus kpadStatus = {};
|
||||||
KPADError kpadError = KPAD_ERROR_UNINITIALIZED;
|
KPADError kpadError = KPAD_ERROR_UNINITIALIZED;
|
||||||
for (int32_t i = 0; i < 4; i++) {
|
for (int32_t i = 0; i < 4; i++) {
|
||||||
if (KPADReadEx((KPADChan) i, &kpadStatus, 1, &kpadError) > 0) {
|
if (KPADReadEx((KPADChan) i, &kpadStatus, 1, &kpadError) > 0) {
|
||||||
if (kpadError == KPAD_ERROR_OK && kpadStatus.extensionType != 0xFF) {
|
if (kpadError == KPAD_ERROR_OK && kpadStatus.extensionType != 0xFF) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user