From 023414fdda4443ed576941d00ac7effc169b6f77 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 4 Jul 2024 17:31:34 +0200 Subject: [PATCH] Limit number of VPADRead attempt to 100 to avoid softlocks even if they should be impossible --- source/InputUtils.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/source/InputUtils.cpp b/source/InputUtils.cpp index 6eb73fb..fa05f20 100644 --- a/source/InputUtils.cpp +++ b/source/InputUtils.cpp @@ -95,9 +95,10 @@ uint32_t remapClassicButtons(uint32_t buttons) { } InputUtils::InputData InputUtils::getControllerInput() { - InputData inputData{}; - VPADStatus vpadStatus{}; + InputData inputData = {}; + VPADStatus vpadStatus = {}; VPADReadError vpadError = VPAD_READ_UNINITIALIZED; + int maxAttempts = 100; do { if (VPADRead(VPAD_CHAN_0, &vpadStatus, 1, &vpadError) > 0 && vpadError == VPAD_READ_SUCCESS) { inputData.trigger = vpadStatus.trigger; @@ -106,10 +107,10 @@ InputUtils::InputData InputUtils::getControllerInput() { } else { OSSleepTicks(OSMillisecondsToTicks(1)); } - } while (vpadError == VPAD_READ_NO_SAMPLES); + } while (--maxAttempts > 0 && vpadError == VPAD_READ_NO_SAMPLES); - KPADStatus kpadStatus{}; - KPADError kpadError = KPAD_ERROR_UNINITIALIZED; + KPADStatus kpadStatus = {}; + KPADError kpadError = KPAD_ERROR_UNINITIALIZED; for (int32_t i = 0; i < 4; i++) { if (KPADReadEx((KPADChan) i, &kpadStatus, 1, &kpadError) > 0) { if (kpadError == KPAD_ERROR_OK && kpadStatus.extensionType != 0xFF) {