]> granicus.if.org Git - libjpeg-turbo/commitdiff
Android: Fix "using JNI after critical get" error
authorDRC <information@libjpeg-turbo.org>
Fri, 26 Oct 2018 13:55:22 +0000 (08:55 -0500)
committerDRC <information@libjpeg-turbo.org>
Mon, 12 Nov 2018 21:03:26 +0000 (15:03 -0600)
We shouldn't be making JNI calls between GetPrimitiveArrayCritical() and
ReleasePrimitiveArrayCritical().  Apparently Android is stricter about
this than desktop Java.

Issue was introduced in 0713c1bb542672257c08782a5a930a577eb20167.

Fixes #300

turbojpeg-jni.c

index eaba670cf3fc91107f342768d10b0f3c44231e6b..93898fba7514574a40fcdea5bd882cc8a88ba91c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C)2011-2016 D. R. Commander.  All Rights Reserved.
+ * Copyright (C)2011-2016, 2018 D. R. Commander.  All Rights Reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are met:
@@ -210,11 +210,11 @@ static jint TJCompressor_compress
        if((*env)->GetArrayLength(env, dst)<(jsize)jpegSize)
                _throwarg("Destination buffer is not large enough");
 
+       if(ProcessSystemProperties(env)<0) goto bailout;
+
        bailif0(srcBuf=(*env)->GetPrimitiveArrayCritical(env, src, 0));
        bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0));
 
-       if(ProcessSystemProperties(env)<0) goto bailout;
-
        if(tjCompress2(handle, &srcBuf[y*actualPitch + x*tjPixelSize[pf]], width,
                pitch, height, pf, &jpegBuf, &jpegSize, jpegSubsamp, jpegQual,
                flags|TJFLAG_NOREALLOC)==-1)
@@ -314,6 +314,8 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFrom
        if((*env)->GetArrayLength(env, dst)<(jsize)jpegSize)
                _throwarg("Destination buffer is not large enough");
 
+       if(ProcessSystemProperties(env)<0) goto bailout;
+
        bailif0(srcOffsets=(*env)->GetPrimitiveArrayCritical(env, jSrcOffsets, 0));
        bailif0(srcStrides=(*env)->GetPrimitiveArrayCritical(env, jSrcStrides, 0));
        for(i=0; i<nc; i++)
@@ -339,8 +341,6 @@ JNIEXPORT jint JNICALL Java_org_libjpegturbo_turbojpeg_TJCompressor_compressFrom
        }
        bailif0(jpegBuf=(*env)->GetPrimitiveArrayCritical(env, dst, 0));
 
-       if(ProcessSystemProperties(env)<0) goto bailout;
-
        if(tjCompressFromYUVPlanes(handle, srcPlanes, width, srcStrides, height,
                subsamp, &jpegBuf, &jpegSize, jpegQual, flags|TJFLAG_NOREALLOC)==-1)
                _throwtj();