Open carl-anders opened 2 years ago
I appreciate your report.
I tried to reproduce it on Windows 10 Home 21H1 19043.1348, but the main thread does not panic. (And it seems that JoyConManager does not recognize the reconnection :sob: )
@carl-anders Does it ALWAYS panics?
It seems to panic 90% of the times I try to reconnect a controller, and when it doesn't panic it hangs somewhere.
I did some basic debugging of the problem, and it seems to be that when it detects a reconnect it assumes that the JoyConDevice::new call was successful. On my joycon that call is only successful about 10% of the times it is run.
I added some dbg! commands, like this in src/joycon/manager.rs
:
Which combined with the earlier example code gives this output when I connect, disconnect and reconnect the joycon:
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedStickParameterLoading,
)
[src\joycon\manager.rs:168] &d = JoyConDevice { hid_device: Connected, serial_number: 9458cb03c2a3, device_type: JoyConL, stick_parameters: StickParameters { dead_zone: 174, range_ratio: 3604 }, , stick_factory_calibration: JoyConSticksCalibration { left: Available { x: AxisCalibration { max: 3235, center: 1906, min: 621 }, y: AxisCalibration { max: 3253, center: 2134, min: 1023 } }, right: Unavailable }, stick_user_calibration: JoyConSticksCalibration { left: Unavailable, right: Unavailable }, imu_offsets: IMUOffsets { x: 350, y: 0, z: 4081 }, imu_factory_calibration: Available { acc_origin_position: XYZ { x: 5, y: 19, z: 212 }, acc_sensitivity_special_coeff: XYZ { x: 16384, y: 16384, z: 16384 }, gyro_origin_position: XYZ { x: 9, y: -8, z: 2 }, gyro_sensitivity_special_coeff: XYZ { x: 15335, y: 15335, z: 15335 } }, imu_user_calibration: Unavailable, color: Color { body: [30, 220, 0], buttons: [0, 40, 0], left_grip: None, right_grip: None } }
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedStickCalibrationLoading,
)
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedStickParameterLoading,
)
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedIMUCalibrationLoading,
)
[src\joycon\manager.rs:168] &d = JoyConDevice { hid_device: Connected, serial_number: 9458cb03c2a3, device_type: JoyConL, stick_parameters: StickParameters { dead_zone: 174, range_ratio: 3604 }, , stick_factory_calibration: JoyConSticksCalibration { left: Available { x: AxisCalibration { max: 3235, center: 1906, min: 621 }, y: AxisCalibration { max: 3253, center: 2134, min: 1023 } }, right: Unavailable }, stick_user_calibration: JoyConSticksCalibration { left: Unavailable, right: Unavailable }, imu_offsets: IMUOffsets { x: 350, y: 0, z: 4081 }, imu_factory_calibration: Available { acc_origin_position: XYZ { x: 5, y: 19, z: 212 }, acc_sensitivity_special_coeff: XYZ { x: 16384, y: 16384, z: 16384 }, gyro_origin_position: XYZ { x: 9, y: -8, z: 2 }, gyro_sensitivity_special_coeff: XYZ { x: 15335, y: 15335, z: 15335 } }, imu_user_calibration: Unavailable, color: Color { body: [30, 220, 0], buttons: [0, 40, 0], left_grip: None, right_grip: None } }
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedColorLoading,
)
[src\joycon\manager.rs:168] &d = JoyConDevice { hid_device: Connected, serial_number: 9458cb03c2a3, device_type: JoyConL, stick_parameters: StickParameters { dead_zone: 174, range_ratio: 3604 }, , stick_factory_calibration: JoyConSticksCalibration { left: Available { x: AxisCalibration { max: 3235, center: 1906, min: 621 }, y: AxisCalibration { max: 3253, center: 2134, min: 1023 } }, right: Unavailable }, stick_user_calibration: JoyConSticksCalibration { left: Unavailable, right: Unavailable }, imu_offsets: IMUOffsets { x: 350, y: 0, z: 4081 }, imu_factory_calibration: Available { acc_origin_position: XYZ { x: 5, y: 19, z: 212 }, acc_sensitivity_special_coeff: XYZ { x: 16384, y: 16384, z: 16384 }, gyro_origin_position: XYZ { x: 9, y: -8, z: 2 }, gyro_sensitivity_special_coeff: XYZ { x: 15335, y: 15335, z: 15335 } }, imu_user_calibration: Unavailable, color: Color { body: [30, 220, 0], buttons: [0, 40, 0], left_grip: None, right_grip: None } }
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedColorLoading,
)
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedIMUOffsetsLoading,
)
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedIMUCalibrationLoading,
)
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedStickCalibrationLoading,
)
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedStickParameterLoading,
)
[src\main.rs:47] a = HidApiError(
HidApiError {
message: "The device is not connected.",
},
)
[src\joycon\manager.rs:169] e = JoyConDeviceError(
FailedStickParameterLoading,
)
[src\joycon\manager.rs:206] &self.devices = {
JoyConSerialNumber(
"9458cb03c2a3",
): Mutex {
data: JoyConDevice { hid_device: Disconnected, serial_number: 9458cb03c2a3, device_type: JoyConL, stick_parameters: StickParameters { dead_zone: 174, range_ratio: 3604 }, , stick_factory_calibration: JoyConSticksCalibration { left: Available { x: AxisCalibration { max: 3235, center: 1906, min: 621 }, y: AxisCalibration { max: 3253, center: 2134, min: 1023 } }, right: Unavailable }, stick_user_calibration: JoyConSticksCalibration { left: Unavailable, right: Unavailable }, imu_offsets: IMUOffsets { x: 350, y: 0, z: 4081 }, imu_factory_calibration: Available { acc_origin_position: XYZ { x: 5, y: 19, z: 212 }, acc_sensitivity_special_coeff: XYZ { x: 16384, y: 16384, z: 16384 }, gyro_origin_position: XYZ { x: 9, y: -8, z: 2 }, gyro_sensitivity_special_coeff: XYZ { x: 15335, y: 15335, z: 15335 } }, imu_user_calibration: Unavailable, color: Color { body: [30, 220, 0], buttons: [0, 40, 0], left_grip: None, right_grip: None } }
,
poisoned: false,
..
},
}
[src\joycon\manager.rs:207] &detected_devices = {}
[src\joycon\manager.rs:208] &k = JoyConSerialNumber(
"9458cb03c2a3",
)
thread '<unnamed>' panicked at 'internal error: entered unreachable code', src\joycon\manager.rs:225:30
(Some duplicates removed)
As you can see, this time when it reconnect, the JoyConDevice::new command had failed (it was not lucky), so it could not find it in the list of devices, and panics.
Also, how come the JoyConDevice::new function is run for already connected joycons? Is it not better to only run it for new and reconnected serial numbers?
Also, how come the JoyConDevice::new function is run for already connected joycons? Is it not better to only run it for new and reconnected serial numbers?
@carl-anders Yes, I admit that I made a mistake. Perhaps I was drinking when I wrote this code. 🍺
Hi. I'm using your library (version 0.6.1), and I'm noticing that with the example code in "standard_full_report.rs" the main thread panics if I
I'm using Windows 10 Pro - 21H1 - 19043.1348 Rust 1.56.1
I have lightly edited the example code to be able to show the error more clearly (without all the normal controller messages), and with a stacktrace
Program output and stacktrace: