Note that there are some explanatory texts on larger screens.

plurals
  1. POHow does JNIEnv global referencing differ from jobject in C?
    primarykey
    data
    text
    <p>I have my JNI environment and jobject objects saved locally as of now. I found that for my JNI to run of ICS and up devices, I need to fix my JNI code. This is the error I get:</p> <pre><code>02-20 10:20:59.523: E/dalvikvm(21629): JNI ERROR (app bug): attempt to use stale local reference 0x38100019 02-20 10:20:59.523: E/dalvikvm(21629): VM aborting 02-20 10:20:59.523: A/libc(21629): Fatal signal 11 (SIGSEGV) at 0xdeadd00d (code=1), thread 21629 </code></pre> <p>I am confused about how to create/destroy these globals, and if I am even doing it right.</p> <p>My application currently runs fine on all pre-ICS devices using this code:</p> <pre><code>BYTE Java_my_eti_commander_RelayAPIModel_00024NativeCalls_InitRelayJava( JNIEnv *env, jobject obj ) { myEnv = (env); myObject = obj; changeID = (*myEnv)-&gt;GetStaticMethodID( myEnv, myObject, "changeItJavaWrapper", "(S)V" ); getID = (*myEnv)-&gt;GetStaticMethodID( myEnv, myObject, "getItJavaWrapper" , "(S)S" ); putID = (*myEnv)-&gt;GetStaticMethodID( myEnv, myObject, "putItJavaWrapper" , "(B)V" ); flushID = (*myEnv)-&gt;GetStaticMethodID( myEnv, myObject, "flushItJavaWrapper" , "()V" ); delayID = (*myEnv)-&gt;GetStaticMethodID( myEnv, myObject, "delayItJavaWrapper" , "(S)V" ); RelayAPI_SetBaud= WrapSetBaud; RelayAPI_get = WrapGetIt; RelayAPI_put = WrapPutIt; RelayAPI_flush = WrapFlushIt; RelayAPI_delay = WrapDelayIt; ... } </code></pre> <p>Under the <code>GetStaticMethodID</code> calls, the RelayAPI_ variables are all function pointers that lead here:</p> <pre><code>void WrapSetBaud( WORD w ) { return (*myEnv)-&gt;CallStaticVoidMethod( myEnv, myObject, changeID, w ); } short WrapGetIt( WORD time ) { return (*myEnv)-&gt;CallStaticShortMethod( myEnv, myObject, getID, time ); } void WrapPutIt( BYTE buff ) { return (*myEnv)-&gt;CallStaticVoidMethod( myEnv, myObject, putID, buff ); } void WrapFlushIt( void ) { return (*myEnv)-&gt;CallStaticVoidMethod( myEnv, myObject, flushID ); } void WrapDelayIt( WORD wait ) { return (*myEnv)-&gt;CallStaticVoidMethod( myEnv, myObject, delayID, wait ); } </code></pre> <p>Finally, it returns to my Java code here:</p> <pre><code>public static void changeItJavaWrapper( short l ) throws IOException { mModelService.changeitJava( l ); } public static void flushItJavaWrapper() { mModelService.flushitJava(); } public static void putItJavaWrapper( byte p ) { mModelService.putitJava( p ); } public static void delayItJavaWrapper( short wait ) { mModelService.delayitJava( wait ); } public static short getItJavaWrapper( short s ) throws IOException { return mModelService.getitJava( s ); } </code></pre> <p>I have changed my initializations to:</p> <pre><code>myEnv = (*env)-&gt;NewGlobalRef(env,obj); myObject = (*env)-&gt;NewGlobalRef(env,obj); </code></pre> <p>But i'm extremely confused with this, as they have the same parameters, and it just doesn't make sense. I can't find documentation for this method anywhere as stupid as that sounds, <a href="http://android-developers.blogspot.com/2011/11/jni-local-reference-changes-in-ics.html" rel="nofollow"><code>this tutorial</code></a>, <a href="http://developer.android.com/training/articles/perf-jni.html" rel="nofollow"><code>this page</code></a>, and <a href="http://docs.oracle.com/javase/1.5.0/docs/guide/jni/spec/design.html#wp1242" rel="nofollow"><code>the oracle docs</code></a> don't have any information on the <code>NewGlobalRef</code> method itself.</p> <p><strong>EDIT</strong></p> <pre><code>jmethodID changeID; jmethodID getID; jmethodID putID; jmethodID flushID; jmethodID delayID; jobject myObject; jclass bluetoothClass; JNIEnv *myEnv; </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