Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wpilibj] Call abort() on Rio on caught Java exception #6420

Merged
merged 4 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions hal/src/main/java/edu/wpi/first/hal/HAL.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Runnable> s_simPeriodicBefore = new ArrayList<>();
Expand Down
15 changes: 15 additions & 0 deletions hal/src/main/native/cpp/jni/HAL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <jni.h>

#include <cassert>
#include <cstdlib>
#include <cstring>

#include <fmt/format.h>
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions wpilibj/src/main/java/edu/wpi/first/wpilibj/RobotBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,11 @@ public static <T extends RobotBase> void startRobot(Supplier<T> robotSupplier) {
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);
Expand Down
Loading