[examples] Fix memory leak in C++ controller command examples (#6306)

This commit is contained in:
Joseph Eng
2024-01-27 23:49:41 -08:00
committed by GitHub
parent 19f1903959
commit 1016e95242
9 changed files with 251 additions and 6 deletions

View File

@@ -111,8 +111,8 @@ frc2::CommandPtr RobotContainer::GetAutonomousCommand() {
// command, then stop at the end.
return frc2::cmd::Sequence(
frc2::InstantCommand(
[this, &exampleTrajectory]() {
m_drive.ResetOdometry(exampleTrajectory.InitialPose());
[this, initialPose = exampleTrajectory.InitialPose()]() {
m_drive.ResetOdometry(initialPose);
},
{})
.ToPtr(),

View File

@@ -84,8 +84,8 @@ frc2::CommandPtr RobotContainer::GetAutonomousCommand() {
// Reset odometry to the initial pose of the trajectory, run path following
// command, then stop at the end.
return frc2::cmd::RunOnce(
[this, &exampleTrajectory] {
m_drive.ResetOdometry(exampleTrajectory.InitialPose());
[this, initialPose = exampleTrajectory.InitialPose()] {
m_drive.ResetOdometry(initialPose);
},
{})
.AndThen(std::move(ramseteCommand))

View File

@@ -93,8 +93,8 @@ frc2::CommandPtr RobotContainer::GetAutonomousCommand() {
// command, then stop at the end.
return frc2::cmd::Sequence(
frc2::InstantCommand(
[this, &exampleTrajectory]() {
m_drive.ResetOdometry(exampleTrajectory.InitialPose());
[this, initialPose = exampleTrajectory.InitialPose()]() {
m_drive.ResetOdometry(initialPose);
},
{})
.ToPtr(),