From 17c397f7ece85e1948a2eca739dd99122f761ea2 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 5 Jun 2023 21:18:49 -0700 Subject: [PATCH] Save the error code before doing any other operation SDL_ClearError() resets the Win32 error code to 0 --- src/hidapi/windows/hid.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hidapi/windows/hid.c b/src/hidapi/windows/hid.c index 81b36729ad..740cbbbefb 100644 --- a/src/hidapi/windows/hid.c +++ b/src/hidapi/windows/hid.c @@ -255,6 +255,9 @@ static void free_hid_device(hid_device *dev) static void register_winapi_error_to_buffer(wchar_t **error_buffer, const WCHAR *op) { + WCHAR system_err_buf[1024]; + DWORD error_code = GetLastError(); + free(*error_buffer); *error_buffer = NULL; @@ -268,9 +271,6 @@ static void register_winapi_error_to_buffer(wchar_t **error_buffer, const WCHAR return; } - WCHAR system_err_buf[1024]; - DWORD error_code = GetLastError(); - DWORD system_err_len = FormatMessageW( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL,