mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[examples] Fix segfault in GearsBot C++ example (#3111)
This fixes a dangling this pointer in the DriveStraight and SetDistanceToBox commands by directly capturing the drivetrain pointer by value instead.
This commit is contained in:
committed by
GitHub
parent
4cf0e5e6db
commit
15be5cbf1f
@@ -11,8 +11,8 @@
|
||||
DriveStraight::DriveStraight(double distance, DriveTrain* drivetrain)
|
||||
: frc2::CommandHelper<frc2::PIDCommand, DriveStraight>(
|
||||
frc2::PIDController(4, 0, 0),
|
||||
[this]() { return m_drivetrain->GetDistance(); }, distance,
|
||||
[this](double output) { m_drivetrain->Drive(output, output); },
|
||||
[drivetrain] { return drivetrain->GetDistance(); }, distance,
|
||||
[drivetrain](double output) { drivetrain->Drive(output, output); },
|
||||
{drivetrain}),
|
||||
m_drivetrain(drivetrain) {
|
||||
m_controller.SetTolerance(0.01);
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
SetDistanceToBox::SetDistanceToBox(double distance, DriveTrain* drivetrain)
|
||||
: frc2::CommandHelper<frc2::PIDCommand, SetDistanceToBox>(
|
||||
frc2::PIDController(-2, 0, 0),
|
||||
[this]() { return m_drivetrain->GetDistanceToObstacle(); }, distance,
|
||||
[this](double output) { m_drivetrain->Drive(output, output); },
|
||||
[drivetrain] { return drivetrain->GetDistanceToObstacle(); },
|
||||
distance,
|
||||
[drivetrain](double output) { drivetrain->Drive(output, output); },
|
||||
{drivetrain}),
|
||||
m_drivetrain(drivetrain) {
|
||||
m_controller.SetTolerance(0.01);
|
||||
|
||||
Reference in New Issue
Block a user