Closed jonathandao0 closed 1 year ago
Calling command lifecycle methods out of order is undefined behavior and shouldn't be done. Checking for this in command impls (some of which are in team code!) is a significant burden, and isn't feasible to do everywhere.
Describe the bug I was helping as a CSA over the weekend with a team that did something improper with running autonomous commands.It took me a while to figure out the root cause, but once I did, it was easy to fix. The StackTrace reported from the error wasn't very clear as to what was causing the issue, which prevented me from resolving it more quickly.
To Reproduce Use the following code:
Robot.java
RobotContainer.java
Steps to reproduce the behavior When running this code, you can select and run the "Do Nothing" and "Auto 1" autonomous commands with no issues. However, when you select and run "Auto 2". the auto will execute successfully, but crash the code immedately afterwards with the following StackTrace:
The error is due to "Auto 2" being a SequentialCommandGroup and trying to execute again once it has completed. When the SequentialCommandGroup ends, the list index resets to -1. Looking into this error more, it is similar to a previous bug report (https://github.com/wpilibsuite/allwpilib/issues/2302).
I'm not exactly sure how this should be handled. Ideally, this should silently fail or provide a warning as the SequentialCommandGroup does run successfully in this case. Otherwise, perhaps a more clear exception should be thrown in this case or the code should crash/error out when the autonomous command is executed again outside of the CommandScheduler when run in autonomousPeriodic? Normally, users should never put
m_autonomousCommand.execute()
in autonomousPeriodic, so I'm not sure this really warrents a change in the first place.