mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Fix array out of bounds exception caused by parallel race group (#1935)
The current index would be set to -1 by the execute method of ParallelRaceGroup, and then an index out of bounds exception would be thrown by the end() method of SequentialCommandGroup. This change bound checks the current command index as well as only calls end at the end of parallel race group rather than during execute.
This commit is contained in:
@@ -69,7 +69,6 @@ public class ParallelRaceGroup extends CommandGroupBase {
|
||||
command.execute();
|
||||
if (command.isFinished()) {
|
||||
m_finished = true;
|
||||
command.end(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,9 +76,7 @@ public class ParallelRaceGroup extends CommandGroupBase {
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
for (Command command : m_commands) {
|
||||
if (!command.isFinished()) {
|
||||
command.end(true);
|
||||
}
|
||||
command.end(!command.isFinished());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,9 @@ public class SequentialCommandGroup extends CommandGroupBase {
|
||||
|
||||
@Override
|
||||
public void end(boolean interrupted) {
|
||||
if (interrupted && !m_commands.isEmpty()) {
|
||||
if (interrupted && !m_commands.isEmpty() && m_currentCommandIndex > -1
|
||||
&& m_currentCommandIndex < m_commands.size()
|
||||
) {
|
||||
m_commands.get(m_currentCommandIndex).end(true);
|
||||
}
|
||||
m_currentCommandIndex = -1;
|
||||
|
||||
Reference in New Issue
Block a user