diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 0a8ca8e0..01783375 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -83,6 +83,7 @@ video tutorials. - Andrew Gutekanst - Stephen Gutekanst - Jonathan Hale + - Daniel Hauser - hdf89shfdfs - Moritz Heinemann - Sylvain Hellegouarch diff --git a/README.md b/README.md index 91e9166c..a527d70b 100644 --- a/README.md +++ b/README.md @@ -133,6 +133,8 @@ information on what to include when reporting a bug. - [Cocoa] Bugfix: Full screen windows were resizable by the user (#2377,#2405) - [Cocoa] Bugfix: Full screen windows were miniaturized when clicked on macOS 10.15 (#2377,#2405) + - [Cocoa] Bugfix: Querying joystick elements could reportedly segfault on macOS + 13 Ventura (#2320) - [Wayland] Added improved fallback window decorations via libdecor (#1639,#1693) - [Wayland] Bugfix: Connecting a mouse after `glfwInit` would segfault (#1450) - [Wayland] Disabled alpha channel for opaque windows on systems lacking diff --git a/src/cocoa_joystick.m b/src/cocoa_joystick.m index 3d306777..f91cf2f8 100644 --- a/src/cocoa_joystick.m +++ b/src/cocoa_joystick.m @@ -137,6 +137,14 @@ static void matchCallback(void* context, return; } + CFArrayRef elements = + IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone); + + // It is reportedly possible for this to fail on macOS 13 Ventura + // if the application does not have input monitoring permissions + if (!elements) + return; + axes = CFArrayCreateMutable(NULL, 0, NULL); buttons = CFArrayCreateMutable(NULL, 0, NULL); hats = CFArrayCreateMutable(NULL, 0, NULL); @@ -180,9 +188,6 @@ static void matchCallback(void* context, name[8], name[9], name[10]); } - CFArrayRef elements = - IOHIDDeviceCopyMatchingElements(device, NULL, kIOHIDOptionsTypeNone); - for (i = 0; i < CFArrayGetCount(elements); i++) { IOHIDElementRef native = (IOHIDElementRef)