Fixed Mac OS X build
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
diff --git a/src/joystick/hidapi/SDL_hidapijoystick.c b/src/joystick/hidapi/SDL_hidapijoystick.c
index 763d80c..1e9e2bd 100644
--- a/src/joystick/hidapi/SDL_hidapijoystick.c
+++ b/src/joystick/hidapi/SDL_hidapijoystick.c
@@ -103,7 +103,7 @@ static struct
Uint32 m_unLastDetect;
#if defined(__WIN32__)
- SDL_threadID m_nThreadID;
+ SDL_threadID m_nThreadID;
WNDCLASSEXA m_wndClass;
HWND m_hwndMsg;
HDEVNOTIFY m_hNotify;
@@ -158,7 +158,7 @@ static LRESULT CALLBACK ControllerWndProc(HWND hwnd, UINT message, WPARAM wParam
switch (wParam) {
case DBT_DEVICEARRIVAL:
if (((DEV_BROADCAST_HDR*)lParam)->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE) {
- SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
+ SDL_HIDAPI_discovery.m_bHaveDevicesChanged = SDL_TRUE;
}
break;
}
@@ -171,10 +171,11 @@ static LRESULT CALLBACK ControllerWndProc(HWND hwnd, UINT message, WPARAM wParam
#if defined(__MACOSX__)
-static void CallbackIOServiceFUNC(void *context, io_iterator_t portIterator)
+static void CallbackIOServiceFunc(void *context, io_iterator_t portIterator)
{
/* Must drain the iterator, or we won't receive new notifications */
- while ((io_object_t entry = IOIteratorNext(portIterator)) != NULL) {
+ io_object_t entry;
+ while ((entry = IOIteratorNext(portIterator)) != 0) {
IOObjectRelease(entry);
*(SDL_bool*)context = SDL_TRUE;
}
@@ -200,21 +201,21 @@ HIDAPI_InitializeDiscovery()
RegisterClassExA(&SDL_HIDAPI_discovery.m_wndClass);
SDL_HIDAPI_discovery.m_hwndMsg = CreateWindowExA(0, "ControllerDetect", NULL, 0, 0, 0, 0, 0, HWND_MESSAGE, NULL, NULL, NULL);
- {
- DEV_BROADCAST_DEVICEINTERFACE_A devBroadcast;
- SDL_memset( &devBroadcast, 0x0, sizeof( devBroadcast ) );
-
- devBroadcast.dbcc_size = sizeof( devBroadcast );
- devBroadcast.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
- devBroadcast.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
-
- /* DEVICE_NOTIFY_ALL_INTERFACE_CLASSES is important, makes GUID_DEVINTERFACE_USB_DEVICE ignored,
- * but that seems to be necessary to get a notice after each individual usb input device actually
- * installs, rather than just as the composite device is seen.
- */
- SDL_HIDAPI_discovery.m_hNotify = RegisterDeviceNotification( SDL_HIDAPI_discovery.m_hwndMsg, &devBroadcast, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES );
- SDL_HIDAPI_discovery.m_bCanGetNotifications = ( SDL_HIDAPI_discovery.m_hNotify != 0 );
- }
+ {
+ DEV_BROADCAST_DEVICEINTERFACE_A devBroadcast;
+ SDL_memset( &devBroadcast, 0x0, sizeof( devBroadcast ) );
+
+ devBroadcast.dbcc_size = sizeof( devBroadcast );
+ devBroadcast.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
+ devBroadcast.dbcc_classguid = GUID_DEVINTERFACE_USB_DEVICE;
+
+ /* DEVICE_NOTIFY_ALL_INTERFACE_CLASSES is important, makes GUID_DEVINTERFACE_USB_DEVICE ignored,
+ * but that seems to be necessary to get a notice after each individual usb input device actually
+ * installs, rather than just as the composite device is seen.
+ */
+ SDL_HIDAPI_discovery.m_hNotify = RegisterDeviceNotification( SDL_HIDAPI_discovery.m_hwndMsg, &devBroadcast, DEVICE_NOTIFY_WINDOW_HANDLE | DEVICE_NOTIFY_ALL_INTERFACE_CLASSES );
+ SDL_HIDAPI_discovery.m_bCanGetNotifications = ( SDL_HIDAPI_discovery.m_hNotify != 0 );
+ }
#endif /* __WIN32__ */
#if defined(__MACOSX__)
@@ -225,9 +226,10 @@ HIDAPI_InitializeDiscovery()
/* Note: IOServiceAddMatchingNotification consumes the reference to matchingDict */
io_iterator_t portIterator = 0;
+ io_object_t entry;
if (IOServiceAddMatchingNotification(SDL_HIDAPI_discovery.m_notificationPort, kIOMatchedNotification, matchingDict, CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator) == 0) {
/* Must drain the existing iterator, or we won't receive new notifications */
- while (io_object_t entry = IOIteratorNext(portIterator)) {
+ while ((entry = IOIteratorNext(portIterator)) != 0) {
IOObjectRelease(entry);
}
} else {
@@ -240,9 +242,10 @@ HIDAPI_InitializeDiscovery()
/* Note: IOServiceAddMatchingNotification consumes the reference to matchingDict */
io_iterator_t portIterator = 0;
+ io_object_t entry;
if (IOServiceAddMatchingNotification(SDL_HIDAPI_discovery.m_notificationPort, kIOMatchedNotification, matchingDict, CallbackIOServiceFunc, &SDL_HIDAPI_discovery.m_bHaveDevicesChanged, &portIterator) == 0) {
/* Must drain the existing iterator, or we won't receive new notifications */
- while (io_object_t entry = IOIteratorNext(portIterator)) {
+ while ((entry = IOIteratorNext(portIterator)) != 0) {
IOObjectRelease(entry);
}
} else {
@@ -803,6 +806,8 @@ HIDAPI_JoystickQuit(void)
{
int i;
+ HIDAPI_ShutdownDiscovery();
+
while (SDL_HIDAPI_devices) {
HIDAPI_DelDevice(SDL_HIDAPI_devices, SDL_FALSE);
}