mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-23 01:21:42 +00:00
Fix IterativeRobot/TimedRobot RobotInit(). (#633)
In C++, it's not legal to call a virtual function from within a constructor, so the user override was never called (the base function is always called). See https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctors While this is technically allowed in Java, also change Java for consistency.
This commit is contained in:
@@ -28,7 +28,12 @@ public class IterativeRobot extends IterativeRobotBase {
|
||||
* Provide an alternate "main loop" via startCompetition().
|
||||
*/
|
||||
public void startCompetition() {
|
||||
// loop forever, calling the appropriate mode-dependent function
|
||||
robotInit();
|
||||
|
||||
// Tell the DS that the robot is ready to be enabled
|
||||
HAL.observeUserProgramStarting();
|
||||
|
||||
// Loop forever, calling the appropriate mode-dependent function
|
||||
while (true) {
|
||||
// Wait for new data to arrive
|
||||
m_ds.waitForData();
|
||||
|
||||
@@ -50,16 +50,6 @@ public abstract class IterativeRobotBase extends RobotBase {
|
||||
|
||||
private Mode m_lastMode = Mode.kNone;
|
||||
|
||||
/**
|
||||
* IterativeRobotBase constructor.
|
||||
*/
|
||||
public IterativeRobotBase() {
|
||||
robotInit();
|
||||
|
||||
// Tell the DS that the robot is ready to be enabled
|
||||
HAL.observeUserProgramStarting();
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide an alternate "main loop" via startCompetition().
|
||||
*/
|
||||
|
||||
@@ -39,7 +39,12 @@ public class TimedRobot extends IterativeRobotBase {
|
||||
* Provide an alternate "main loop" via startCompetition().
|
||||
*/
|
||||
public void startCompetition() {
|
||||
// loop forever, calling the appropriate mode-dependent function
|
||||
robotInit();
|
||||
|
||||
// Tell the DS that the robot is ready to be enabled
|
||||
HAL.observeUserProgramStarting();
|
||||
|
||||
// Loop forever, calling the appropriate mode-dependent function
|
||||
m_startLoop = true;
|
||||
m_loop.startPeriodic(m_period);
|
||||
while (true) {
|
||||
|
||||
Reference in New Issue
Block a user