Fixed bug 3932 - Android, GetDisplayDPI release local reference
authorSam Lantinga <slouken@libsdl.org>
Wed, 01 Nov 2017 17:30:02 -0700
changeset 11665861f42ecf09a
parent 11664 c677bf234773
child 11666 b2d2705511d1
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.
src/core/android/SDL_android.c
     1.1 --- a/src/core/android/SDL_android.c	Wed Nov 01 10:07:04 2017 -0700
     1.2 +++ b/src/core/android/SDL_android.c	Wed Nov 01 17:30:02 2017 -0700
     1.3 @@ -1065,9 +1065,19 @@
     1.4      float nativeYdpi = (*env)->GetFloatField(env, jDisplayObj, fidYdpi);
     1.5      int nativeDdpi = (*env)->GetIntField(env, jDisplayObj, fidDdpi);
     1.6  
     1.7 -    *ddpi = (float)nativeDdpi;
     1.8 -    *xdpi = nativeXdpi;
     1.9 -    *ydpi = nativeYdpi;
    1.10 +
    1.11 +    (*env)->DeleteLocalRef(env, jDisplayObj);
    1.12 +    (*env)->DeleteLocalRef(env, jDisplayClass);
    1.13 +
    1.14 +    if (ddpi) {
    1.15 +        *ddpi = (float)nativeDdpi;
    1.16 +    }
    1.17 +    if (xdpi) {
    1.18 +        *xdpi = nativeXdpi;
    1.19 +    }
    1.20 +    if (ydpi) {
    1.21 +        *ydpi = nativeYdpi;
    1.22 +    }
    1.23  
    1.24      return 0;
    1.25  }