I was debugging an issue with a bluetooth gamepad, and found that its hid report descriptor had its hat using the following descriptor. I did testing with the latest version of InputSystem (1.19.0)
0xA1, 0x00, // Collection (Physical)
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x39, // Usage (Hat switch)
0x15, 0x01, // Logical Minimum (1)
0x25, 0x08, // Logical Maximum (8)
0x35, 0x00, // Physical Minimum (0)
0x46, 0x3B, 0x01, // Physical Maximum (315)
0x65, 0x12, // Unit (System: SI Rotation, Length: Centimeter)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0x81, 0x42, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
0xC0, // End Collection
This causes the following error (the stack trace is about 1000 lines long and just repeats this):
IndexOutOfRangeException: Index was outside the bounds of the array.
at UnityEngine.InputSystem.Layouts.InputDeviceBuilder.InsertControlBitRangeNode (UnityEngine.InputSystem.InputDevice+ControlBitRangeNode& parent, UnityEngine.InputSystem.InputControl control, System.Int32& controlIndiciesNextFreeIndex, System.UInt16 startOffset) [0x001aa] in /home/sanjay/Code/PlasticBand-Unity/Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Devices/InputDeviceBuilder.cs:1010
at UnityEngine.InputSystem.Layouts.InputDeviceBuilder.InsertControlBitRangeNode (UnityEngine.InputSystem.InputDevice+ControlBitRangeNode& parent, UnityEngine.InputSystem.InputControl control, System.Int32& controlIndiciesNextFreeIndex, System.UInt16 startOffset) [0x001aa] in /home/sanjay/Code/PlasticBand-Unity/Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Devices/InputDeviceBuilder.cs:1010
at UnityEngine.InputSystem.Layouts.InputDeviceBuilder.InsertControlBitRangeNode (UnityEngine.InputSystem.InputDevice+ControlBitRangeNode& parent, UnityEngine.InputSystem.InputControl control, System.Int32& controlIndiciesNextFreeIndex, System.UInt16 startOffset) [0x001aa] in /home/sanjay/Code/PlasticBand-Unity/Library/PackageCache/com.unity.inputsystem@1.7.0/InputSystem/Devices/InputDeviceBuilder.cs:1010
Changing the hat to a more standard hat does fix the problem however.
0xA1, 0x00, // Collection (Physical)
0x05, 0x01, // Usage Page (Generic Desktop Ctrls)
0x09, 0x39, // Usage (Hat switch)
0x15, 0x01, // Logical Minimum (1)
0x25, 0x08, // Logical Maximum (8)
0x35, 0x00, // Physical Minimum (0)
0x46, 0x3B, 0x01, // Physical Maximum (315)
0x65, 0x12, // Unit (System: SI Rotation, Length: Centimeter)
0x75, 0x04, // Report Size (4)
0x95, 0x01, // Report Count (1)
0x81, 0x42, // Input (Data,Var,Abs,No Wrap,Linear,Preferred State,Null State)
0x81, 0x01, // Input (Const,Array,Abs,No Wrap,Linear,Preferred
0xC0, // End Collection
This issue is related to Custom bluetooth gamepad not recognized