diff --git a/hal/src/main/java/edu/wpi/first/hal/HAL.java b/hal/src/main/java/edu/wpi/first/hal/HAL.java index d9eb8d599d..68cf0e8dee 100644 --- a/hal/src/main/java/edu/wpi/first/hal/HAL.java +++ b/hal/src/main/java/edu/wpi/first/hal/HAL.java @@ -75,6 +75,9 @@ public final class HAL extends JNIWrapper { */ public static native void exitMain(); + /** Terminates the executable (at the native level). Does nothing in simulation. */ + public static native void terminate(); + private static native void simPeriodicBeforeNative(); private static final List s_simPeriodicBefore = new ArrayList<>(); diff --git a/hal/src/main/native/cpp/jni/HAL.cpp b/hal/src/main/native/cpp/jni/HAL.cpp index 6f486e5fc0..9918f46d6e 100644 --- a/hal/src/main/native/cpp/jni/HAL.cpp +++ b/hal/src/main/native/cpp/jni/HAL.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -82,6 +83,20 @@ Java_edu_wpi_first_hal_HAL_exitMain HAL_ExitMain(); } +/* + * Class: edu_wpi_first_hal_HAL + * Method: terminate + * Signature: ()V + */ +JNIEXPORT void JNICALL +Java_edu_wpi_first_hal_HAL_terminate + (JNIEnv*, jclass) +{ +#ifdef __FRC_ROBORIO__ + std::abort(); +#endif +} + /* * Class: edu_wpi_first_hal_HAL * Method: simPeriodicBeforeNative diff --git a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java index 8952406337..3c3035ce13 100644 --- a/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java +++ b/wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java @@ -453,6 +453,11 @@ public abstract class RobotBase implements AutoCloseable { runRobot(robotSupplier); } + // On RIO, this will just terminate rather than shutting down cleanly (it's a no-op in sim). + // It's not worth the risk of hanging on shutdown when we want the code to restart as quickly + // as possible. + HAL.terminate(); + HAL.shutdown(); System.exit(0);