robotpy-wpilib icon indicating copy to clipboard operation
robotpy-wpilib copied to clipboard

Race condition in getStickButton

Open virtuald opened this issue 7 years ago • 1 comments

If a user calls DriverStation.getStickButton in robotInit() (for example, when initializing a JoystickButton command) , they'll get a warning that the button does not exist yet. This happens because the initial count of all buttons is zero, and the count doesn't get updated until the DS thread executes at least a single loop.

WPILib seems like it would have the same issue, except that presumably their thread gets executed in time and so the warning never occurs (or people just ignore it).

A workaround could be just to initialize the button count to the max number. Once the ds thread updates, once the user calls the thing again they'll get the warning if it's needed.

Reference: https://www.chiefdelphi.com/forums/showthread.php?threadid=166029

virtuald avatar Jul 19 '18 14:07 virtuald

Bug filed upstream at https://github.com/wpilibsuite/allwpilib/issues/1198

virtuald avatar Jul 19 '18 15:07 virtuald