-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
It seems that the SDL_hid_device_info
structure, which has been recently made available according to the logs, breaks the support with Microsoft Visual Studio, at least starting from VS2019 on ARM64.
If your project includes SDL_hidapi.h, then you can get this message on the console:
SDL_hidapi.h(97,33): error C2220: the following warning is treated as an error
SDL_hidapi.h(97,33): warning C4121: 'SDL_hid_device_info': alignment of a member was sensitive to packing
This issue happens because the SDL_hid_device_info
structure has been poorly written.
At the time of writing, that structure is:
typedef struct SDL_hid_device_info
{
/** Platform-specific device path */
char *path;
/** Device Vendor ID */
unsigned short vendor_id;
/** Device Product ID */
unsigned short product_id;
/** Serial Number */
wchar_t *serial_number;
/** Device Release Number in binary-coded decimal,
also known as Device Version Number */
unsigned short release_number;
/** Manufacturer String */
wchar_t *manufacturer_string;
/** Product string */
wchar_t *product_string;
/** Usage Page for this Device/Interface
(Windows/Mac only). */
unsigned short usage_page;
/** Usage for this Device/Interface
(Windows/Mac only).*/
unsigned short usage;
/** The USB interface which this logical device
represents.
* Valid on both Linux implementations in all cases.
* Valid on the Windows implementation only if the device
contains more than one interface. */
int interface_number;
/** Additional information about the USB interface.
Valid on libusb and Android implementations. */
int interface_class;
int interface_subclass;
int interface_protocol;
/** Pointer to the next device */
struct SDL_hid_device_info *next;
} SDL_hid_device_info;
As you can see, there are several small size items mixed with larger size items, which can cause troubles if the user changes the default alignment or the packing of the structure and it seems that MSVC does not like it.
A better written code would be a structure with items sorted by size, for example like this;
typedef struct SDL_hid_device_info
{
/** Platform-specific device path */
char *path;
/** Serial Number */
wchar_t *serial_number;
/** Manufacturer String */
wchar_t *manufacturer_string;
/** Product string */
wchar_t *product_string;
/** Pointer to the next device */
struct SDL_hid_device_info *next;
/** The USB interface which this logical device
represents.
* Valid on both Linux implementations in all cases.
* Valid on the Windows implementation only if the device
contains more than one interface. */
int interface_number;
/** Additional information about the USB interface.
Valid on libusb and Android implementations. */
int interface_class;
int interface_subclass;
int interface_protocol;
/** Device Vendor ID */
unsigned short vendor_id;
/** Device Product ID */
unsigned short product_id;
/** Device Release Number in binary-coded decimal,
also known as Device Version Number */
unsigned short release_number;
/** Usage Page for this Device/Interface
(Windows/Mac only). */
unsigned short usage_page;
/** Usage for this Device/Interface
(Windows/Mac only).*/
unsigned short usage;
} SDL_hid_device_info;
to avoid useless waste of space.
However, since this code has been already made available, an alternative solution can be applied by including also _M_ARM64
inside begin_code.h
, since we are talking about a 64bit platform:
Line 110 in 94ed6b0
#ifdef _M_X64 |
But I don't know how much this can break compatibility for existing versions of SDL2.DLL
.