Commit 9192c93e90219fede36d1f102b9661f9002fbea8

Sam Lantinga 2017-11-01T17:30:02

Fixed bug 3932 - Android, GetDisplayDPI release local reference Sylvain When writing JNI code, one has to make sure all local references are released otherwise the app end up crashing.

diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index bfc1c71..78ef776 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -1065,9 +1065,19 @@ int Android_JNI_GetDisplayDPI(float *ddpi, float *xdpi, float *ydpi)
     float nativeYdpi = (*env)->GetFloatField(env, jDisplayObj, fidYdpi);
     int nativeDdpi = (*env)->GetIntField(env, jDisplayObj, fidDdpi);
 
-    *ddpi = (float)nativeDdpi;
-    *xdpi = nativeXdpi;
-    *ydpi = nativeYdpi;
+
+    (*env)->DeleteLocalRef(env, jDisplayObj);
+    (*env)->DeleteLocalRef(env, jDisplayClass);
+
+    if (ddpi) {
+        *ddpi = (float)nativeDdpi;
+    }
+    if (xdpi) {
+        *xdpi = nativeXdpi;
+    }
+    if (ydpi) {
+        *ydpi = nativeYdpi;
+    }
 
     return 0;
 }