| Summary: | joystick: Ensure HIDAPI is initialized before calling it | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Andrew Eikum <aeikum> |
| Component: | joystick | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | normal | ||
| Priority: | P2 | CC: | cameron.gutman, sezeroz |
| Version: | HG 2.0 | ||
| Hardware: | x86_64 | ||
| OS: | Linux | ||
| Attachments: |
[PATCH] joystick/hidapi: Initialize hidapi in HIDAPI_IsDevicePresent
joystick: Ensure HIDAPI is initialized before calling it |
||
A better solution might be to avoid calling into other joystick backends from JoystickInit methods, but that's beyond me. I don't think calling hid_init() is required in our scenario. The function is documented as follows: /** @brief Initialize the HIDAPI library. This function initializes the HIDAPI library. Calling it is not strictly necessary, as it will be called automatically by hid_enumerate() and any of the hid_open_*() functions if it is needed. This function should be called at the beginning of execution however, if there is a chance of HIDAPI handles being opened by different threads simultaneously. @ingroup API @returns This function returns 0 on success and -1 on error. */ int HID_API_EXPORT HID_API_CALL hid_init(void); So calling HIDAPI_IsDevicePresent() from an arbitrary JoystickInit() is safe because it's guaranteed to be on the same thread that will later call HIDAPI's JoystickInit(). Oh! Good find! That shows this is a bug in the multiple backends code from Bug 4554. I'll make a note over there. Created attachment 3912 [details]
joystick: Ensure HIDAPI is initialized before calling it
This regressed because of d9699df941ac "Don't call hid_enumerate() if the HIDAPI drivers are all disabled". I think it's clear that calling into HIDAPI before it is initialized is going to continue to cause problems. Here's a patch that just initializes HIDAPI before we call into it, and also makes HIDAPI's Init method safe to call more than once.
Reopening for review |
Created attachment 3896 [details] [PATCH] joystick/hidapi: Initialize hidapi in HIDAPI_IsDevicePresent The Linux joystick backend calls HIDAPI_IsDevicePresent during its Init method. This occurs _before_ the HIDAPI joystick backend's Init method is called, in other words, before hid_init() is called. Invoking hidapi methods before hid_init() is invalid. Unlike the SDL JoystickInit methods, hid_init() is safe to call more than once, so let's do that twice in the HIDAPI joystick code.