Fix CheckJNI abort with rumble values greater than 0x7FFF

This commit is contained in:
Cameron Gutman 2020-04-07 19:21:24 -07:00
parent 800f97ae85
commit 07fabc0663

View File

@ -304,7 +304,10 @@ void BridgeClConnectionTerminated(int errorCode) {
void BridgeClRumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsigned short highFreqMotor) { void BridgeClRumble(unsigned short controllerNumber, unsigned short lowFreqMotor, unsigned short highFreqMotor) {
JNIEnv* env = GetThreadEnv(); JNIEnv* env = GetThreadEnv();
(*env)->CallStaticVoidMethod(env, GlobalBridgeClass, BridgeClRumbleMethod, controllerNumber, lowFreqMotor, highFreqMotor); // The seemingly redundant short casts are required in order to convert the unsigned short to a signed short.
// If we leave it as an unsigned short, CheckJNI will fail when the value exceeds 32767. The cast itself is
// fine because the Java code treats the value as unsigned even though it's stored in a signed type.
(*env)->CallStaticVoidMethod(env, GlobalBridgeClass, BridgeClRumbleMethod, controllerNumber, (short)lowFreqMotor, (short)highFreqMotor);
if ((*env)->ExceptionCheck(env)) { if ((*env)->ExceptionCheck(env)) {
// We will crash here // We will crash here
(*JVM)->DetachCurrentThread(JVM); (*JVM)->DetachCurrentThread(JVM);