mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51: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:
@@ -26,16 +26,13 @@ void ParallelRaceGroup::Execute() {
|
||||
commandRunning->Execute();
|
||||
if (commandRunning->IsFinished()) {
|
||||
m_finished = true;
|
||||
commandRunning->End(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ParallelRaceGroup::End(bool interrupted) {
|
||||
for (auto& commandRunning : m_commands) {
|
||||
if (!commandRunning->IsFinished()) {
|
||||
commandRunning->End(true);
|
||||
}
|
||||
commandRunning->End(!commandRunning->IsFinished());
|
||||
}
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,9 @@ void SequentialCommandGroup::Execute() {
|
||||
}
|
||||
|
||||
void SequentialCommandGroup::End(bool interrupted) {
|
||||
if (interrupted && !m_commands.empty()) {
|
||||
if (interrupted && !m_commands.empty() &&
|
||||
m_currentCommandIndex != invalid_index &&
|
||||
m_currentCommandIndex < m_commands.size()) {
|
||||
m_commands[m_currentCommandIndex]->End(interrupted);
|
||||
}
|
||||
m_currentCommandIndex = invalid_index;
|
||||
|
||||
Reference in New Issue
Block a user