Skip to content

Commit 5e45845

Browse files
committed
Fix HID hard crash on Mac
1 parent 1d2f230 commit 5e45845

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

src/qz/communication/HidUtilities.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.hid4java.HidDevice;
88
import org.hid4java.HidManager;
99
import org.hid4java.HidServices;
10+
import qz.utils.SystemUtilities;
1011

1112
import javax.usb.util.UsbUtil;
1213
import java.util.List;
@@ -47,13 +48,20 @@ public static HidDevice findDevice(Short vendorId, Short productId) {
4748
}
4849

4950
List<HidDevice> devices = service.getAttachedHidDevices();
50-
for(HidDevice device : devices) {
51-
if (device.isVidPidSerial(vendorId, productId, null)) {
52-
return device;
51+
HidDevice device = null;
52+
for(HidDevice d : devices) {
53+
if (d.isVidPidSerial(vendorId, productId, null)) {
54+
device = d;
5355
}
5456
}
5557

56-
return null;
58+
// FIXME: Prevent hard crash on OSX
59+
// Per upstream Mac bug https://github.com/gary-rowe/hid4java/issues/37
60+
if (SystemUtilities.isMac()) {
61+
service.shutdown();
62+
}
63+
64+
return device;
5765
}
5866

5967
}

0 commit comments

Comments
 (0)