Log in or register to post comments

JNI in renderFrame

February 3, 2011 - 11:09am #6

I'm trying to trigger some Java code when certain trackables are identified. Right now, I'm able to accomplish this via JNI:

jmethodID method = javaEnv->GetMethodID(javaClass, "myJavaMethod", "(I)V");
javaEnv->CallVoidMethod(javaObj, method, b);

But, it seems that this introduces some instability with the rendering code, causing the application to crash intermittently. If I remove the JNI calls, the crashes go away.

What's the best (and most stable) way to execute small bits of Java code when a trackable is identified in the camera's view?

Thanks...

Re: JNI in renderFrame

February 3, 2011 - 11:22am #5

I'm surprised you're getting a crash, if possible could you send the project to

?

Do note that the renderFrame native method is called in the GLThread, which cannot modify Android UI elements in Java. You will need to set up a Handler to pass messages to the UIThread if your Java method is trying to change the UI. There is an example of this in the Dominoes sample application.

- Kim

Re: JNI in renderFrame

February 7, 2011 - 4:29pm #4

Kim,

I'm modifying the UI elements on the UI thread. The crash is intermittent.

Do you need the .apk or the full source?

Thanks...

Re: JNI in renderFrame

February 8, 2011 - 5:34am #3

Full source is helpful for debugging purposes, but an apk would be sufficient to see if I can reproduce the problem on my end. In that case could you also share your JNI calls here, or describe exactly what you are doing? Are you calling up to Java directly from the renderFrame method, or are you storing the Java environment and using it later? What is your Java code doing on the other end of this call, and is it thread safe? Which class are you placing your Java methods in? We need to get a clear idea of what your code is doing (and how it is doing it) to help debug this issue.

- Kim

Re: JNI in renderFrame

February 8, 2011 - 11:27am #2

For some reason, I am unable to send you the project. I have tried with multiple email accounts. I'm trying to send a .zip file that is about 2MB. Is there an alternate way to get this to you?

Thanks...

Re: JNI in renderFrame

February 9, 2011 - 9:19am #1

Alright, I sent you a link to the file. I'm interested to know what you are able to deduce regarding the intermittent crashes.

Thanks...

Log in or register to post comments