From 84e7d5906c764899cbbf18bf7e3c228ca3281470 Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Tue, 15 Sep 2015 21:32:51 -0700 Subject: [PATCH] Java: Use Global instead of WeakGlobal for callbacks. For some reason, weak globals don't work as they (unexpectedly) are getting destroyed even though we save the callback in a map at the Java level. --- java/lib/NetworkTablesJNI.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/java/lib/NetworkTablesJNI.cpp b/java/lib/NetworkTablesJNI.cpp index 80fbc236f6..8156b9a013 100644 --- a/java/lib/NetworkTablesJNI.cpp +++ b/java/lib/NetworkTablesJNI.cpp @@ -859,7 +859,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI // the shared pointer to the weak global will keep it around until the // entry listener is destroyed auto listener_global = - std::make_shared>(envouter, listener); + std::make_shared>(envouter, listener); // cls is a temporary here; cannot be used within callback functor jclass cls = envouter->GetObjectClass(listener); @@ -884,8 +884,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI { // get the handler - auto handler = listener_global->obj(env); - if (!handler) goto done; // can happen due to weak reference + auto handler = listener_global->obj(); // convert the value into the appropriate Java type jobject jobj = ToJavaObject(env, *value); @@ -927,7 +926,7 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI // the shared pointer to the weak global will keep it around until the // entry listener is destroyed auto listener_global = - std::make_shared>(envouter, listener); + std::make_shared>(envouter, listener); // cls is a temporary here; cannot be used within callback functor jclass cls = envouter->GetObjectClass(listener); @@ -950,8 +949,8 @@ JNIEXPORT jint JNICALL Java_edu_wpi_first_wpilibj_networktables_NetworkTablesJNI { // get the handler - auto handler = listener_global->obj(env); - if (!handler) goto done; // can happen due to weak reference + auto handler = listener_global->obj(); + //if (!handler) goto done; // can happen due to weak reference // convert into the appropriate Java type jobject jobj = ToJavaObject(env, conn);