mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[cmd2] CommandScheduler::Cancel(): Don't mutate in for loop (#8743)
Erasing elements from a container while iterating over the container may not be well-defined.
This commit is contained in:
@@ -315,11 +315,15 @@ void CommandScheduler::Cancel(Command* command,
|
||||
for (auto&& action : m_impl->interruptActions) {
|
||||
action(*command, interruptor);
|
||||
}
|
||||
wpi::util::SmallVector<Subsystem*, 8> toErase;
|
||||
for (auto&& requirement : m_impl->requirements) {
|
||||
if (requirement.second == command) {
|
||||
m_impl->requirements.erase(requirement.first);
|
||||
toErase.push_back(requirement.first);
|
||||
}
|
||||
}
|
||||
for (auto* subsystem : toErase) {
|
||||
m_impl->requirements.erase(subsystem);
|
||||
}
|
||||
m_watchdog.AddEpoch(command->GetName() + ".End(true)");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user