diff --git a/commandsv2/src/main/native/cpp/frc2/command/CommandScheduler.cpp b/commandsv2/src/main/native/cpp/frc2/command/CommandScheduler.cpp index 1685d62a2a..a43adf2fb2 100644 --- a/commandsv2/src/main/native/cpp/frc2/command/CommandScheduler.cpp +++ b/commandsv2/src/main/native/cpp/frc2/command/CommandScheduler.cpp @@ -315,11 +315,15 @@ void CommandScheduler::Cancel(Command* command, for (auto&& action : m_impl->interruptActions) { action(*command, interruptor); } + wpi::util::SmallVector 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)"); }