[PATCH v6 0/2] MR11192: xinput1_3: Initialize controller state only on success in controller_init.
-- v6: xinput1_3: Initialize controller state only on success in controller_init. xinput1_3: Initialize state with the previous state in read_controller_state. https://gitlab.winehq.org/wine/wine/-/merge_requests/11192
From: Shaun Ren <sren@codeweavers.com> This allows dwPacketNumber to be incremented properly, and also allows others fields to retain their previous values in case of read failure. --- dlls/xinput1_3/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dlls/xinput1_3/main.c b/dlls/xinput1_3/main.c index a7657b125af..d25c234b5cf 100644 --- a/dlls/xinput1_3/main.c +++ b/dlls/xinput1_3/main.c @@ -601,6 +601,8 @@ static void read_controller_state(struct xinput_controller *controller) status = HidP_GetUsages(HidP_Input, HID_USAGE_PAGE_BUTTON, 0, buttons, &button_length, controller->hid.preparsed, report_buf, report_len); if (status != HIDP_STATUS_SUCCESS) WARN("HidP_GetUsages HID_USAGE_PAGE_BUTTON returned %#lx\n", status); + get_current_state(controller - controllers, &state); + state.Gamepad.wButtons = 0; for (i = 0; i < button_length; i++) { -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11192
From: Shaun Ren <sren@codeweavers.com> --- dlls/xinput1_3/main.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dlls/xinput1_3/main.c b/dlls/xinput1_3/main.c index d25c234b5cf..8530b028d5e 100644 --- a/dlls/xinput1_3/main.c +++ b/dlls/xinput1_3/main.c @@ -374,13 +374,15 @@ static BOOL controller_init(struct xinput_controller *controller, PHIDP_PREPARSE if (!(controller->hid.input_report_buf = calloc(1, controller->hid.caps.InputReportByteLength))) goto failed; if (!(controller->hid.output_report_buf = calloc(1, controller->hid.caps.OutputReportByteLength))) goto failed; - set_current_state(controller - controllers, &state); memset(&controller->vibration, 0, sizeof(controller->vibration)); lstrcpynW(controller->device_path, device_path, MAX_PATH); controller->enabled = FALSE; controller->device = device; - if (controller_enable(controller)) return TRUE; + if (!controller_enable(controller)) goto failed; + + set_current_state(controller - controllers, &state); + return TRUE; failed: free(controller->hid.input_report_buf); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/11192
This merge request was approved by Rémi Bernon. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/11192
participants (3)
-
Rémi Bernon (@rbernon) -
Shaun Ren -
Shaun Ren (@shaunren)