Skip to content

Commit

Permalink
fix scheduledCommands.erase() being called in the same sets iterator
Browse files Browse the repository at this point in the history
  • Loading branch information
kytpbs committed May 6, 2024
1 parent 6a73ca8 commit 3388b06
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ void CommandScheduler::Run() {
m_impl->inRunLoop = true;
bool isDisabled = frc::RobotState::IsDisabled();
// Run scheduled commands, remove finished commands.
auto toRemove = std::vector<Command*>(m_impl->scheduledCommands.size());
for (Command* command : m_impl->scheduledCommands) {
if (isDisabled && !command->RunsWhenDisabled()) {
Cancel(command, std::nullopt);
Expand All @@ -216,14 +217,20 @@ void CommandScheduler::Run() {
}
m_impl->endingCommands.erase(command);

m_impl->scheduledCommands.erase(command);
toRemove.push_back(command);
for (auto&& requirement : command->GetRequirements()) {
m_impl->requirements.erase(requirement);
}

m_watchdog.AddEpoch(command->GetName() + ".End(false)");
}
}

// remove the commands that should be removed
for (auto&& command : toRemove) {
m_impl->scheduledCommands.erase(command);
}

m_impl->inRunLoop = false;

for (Command* command : m_impl->toSchedule) {
Expand Down

0 comments on commit 3388b06

Please sign in to comment.