Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid passing large float arrays from native to java via jni. Getting error if over certain size
    primarykey
    data
    text
    <p>I am wanting to pass a single large array of floats anywhere up too and beyond float[100000]. I have a setup successfully passing an array of size 212. But any larger and it crashes giving the following error message in the logcat:</p> <p>"Fatal signal 11 (SIGSEGV) at 0xbe949000 (code=1)"</p> <h2>My code</h2> <p><strong>Native function</strong></p> <pre><code>NIEXPORT jfloatArray JNICALL Java_carron_graphics_benchmark_NativeWrapper_getArrayNative(JNIEnv * env, jclass cls) { int tempSize = mParticleSystem-&gt;mSizeOfSystem*2; jfloat cArray[tempSize]; jsize len = sizeof(cArray); jfloatArray jArray = (*env).NewFloatArray(len); if (jArray != NULL) { jint i; for (i = 0; i &lt; tempSize; i++) { cArray[i] = mParticleSystem-&gt;mParticlePositions[i]; } (*env).SetFloatArrayRegion(jArray, 0, len, cArray); } return jArray; } </code></pre> <p><strong>Java</strong> Pretty straight forward simply grabbing the array. If I create and pass a float array larger than 212 though I get the error as shown above.</p> <pre><code>float tempArray[] = NativeWrapper.getArrayNative(); </code></pre> <p><strong>Has anyone encountered this problem or can see how I can get around this limit? Also I apologise if this question has been answered already, I could not find this specific issue nor an answer. Any help will be appreciated :)</strong></p> <p>EDIT:</p> <p>For updating a global jfloatArray to avoid the garbage collector when frequently fetching an array through jni.</p> <pre><code>static jfloatArray gArray = NULL; JNIEXPORT jfloatArray JNICALL Java_carron_graphics_benchmark_NativeWrapper_getArrayNative(JNIEnv * env, jclass cls) { int arrayLength = mParticleSystem-&gt;mSizeOfSystem*2; if (gArray == NULL) { // create array jfloatArray jArray; jArray = env-&gt;NewFloatArray(arrayLength); gArray = (jfloatArray)env-&gt;NewGlobalRef(jArray); } // Update global env-&gt;SetFloatArrayRegion(gArray, 0, arrayLength, mParticleSystem-&gt;mParticlePositions); return gArray; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload