[command] Reorder Scheduler operations (#4261)

Fixes several cases where calling scheduler operations from a command callback could result in NPEs or other issues.

Co-authored-by: Tyler Veness <calcmogul@gmail.com>
This commit is contained in:
Starlight220
2022-06-16 09:32:16 +03:00
committed by GitHub
parent e61028cb18
commit 9ac9b69aa2
7 changed files with 438 additions and 25 deletions

View File

@@ -151,11 +151,11 @@ void CommandScheduler::Schedule(bool interruptible, Command* command) {
Cancel(cmdToCancel);
}
}
command->Initialize();
m_impl->scheduledCommands[command] = CommandState{interruptible};
for (auto&& requirement : requirements) {
m_impl->requirements[requirement] = command;
}
command->Initialize();
for (auto&& action : m_impl->initActions) {
action(*command);
}
@@ -336,17 +336,17 @@ void CommandScheduler::Cancel(Command* command) {
if (find == m_impl->scheduledCommands.end()) {
return;
}
command->End(true);
for (auto&& action : m_impl->interruptActions) {
action(*command);
}
m_watchdog.AddEpoch(command->GetName() + ".End(true)");
m_impl->scheduledCommands.erase(find);
for (auto&& requirement : m_impl->requirements) {
if (requirement.second == command) {
m_impl->requirements.erase(requirement.first);
}
}
command->End(true);
for (auto&& action : m_impl->interruptActions) {
action(*command);
}
m_watchdog.AddEpoch(command->GetName() + ".End(true)");
}
void CommandScheduler::Cancel(wpi::span<Command* const> commands) {