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:
Matt
2019-10-18 07:55:14 -07:00
committed by Peter Johnson
parent 7bd69e591c
commit bb0b207d2f
6 changed files with 64 additions and 10 deletions

View File

@@ -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;
}

View File

@@ -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;