[Solved] Issue with OpenGL on Android 5 (Lollipop)


#1

Using OpenGL causes a crash on Android 5, as soon as the openGL context is attached to a component, I'm getting this:

 

JNI ERROR (app bug): attempt to pass an instance of com.mycompany.myapp.myapp$OpenGLView as argument 1 to void com.mycompany.myapp.myapp.deleteView(com.mycompany.myapp.myapp$ComponentPeerView)

art/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION : bad arguments passed to void com.mycompany.myapp.myapp.deleteView(com.mycompany.myapp.myapp$ComponentPeerView) (see above for details)

 

Any idea what could cause this ? The same code works in Android 4.x.

 


#2

Ok, it seems that the new android runtime (ART) is way more strict than Dalvik, which causes some JNI calls to be rejected.

Here's how I solved my issue with OpenGL:

In juce_android_JNIHelpers.h, I added this at line 354:

METHOD (deleteGLView,           "deleteOpenGLView",         "(L" JUCE_ANDROID_ACTIVITY_CLASSPATH "$OpenGLView;)V") \

Then in juce_OpenGL_android.h, I changed line 62 to:

android.activity.callVoidMethod (JuceAppActivity.deleteOpenGLView, glView.get());

And finally,  I added a new method in the activity's code:


public final void deleteOpenGLView (OpenGLView view)
    {
        ViewGroup group = (ViewGroup) (view.getParent());
        if (group != null)
            group.removeView (view);
    }
 

This seems to be mandatory since ART doesn't allow the OpenGLView to be casted to a ComponentPeerView.

 


#3

Good work sir! 


#4

Thanks! I can add something along these lines, but the line numbers and files you're talking about don't match up with anything I see here.. Are you using an old version?


#5

Indeed I'm using an older version, because it seems the newer Juce version has some other issues with Android 5, but they're probably all related to this kind of error (JNI call rejecteds by ART)

 


#6

Ok, well I pushed something yesterday that should help with this. Thanks for letting me know!


#7

On the topic of OpenGL cleanup and shutdown on Android:

the OpenGLRenderer::openGLContextClosing callback is never called on Android.

The only place it is called is in OpenGLContext::CachedImageshutdownOnThread which is only called by OpenGLContext::CachedImage::run which is #if'd out on Android (JUCE_OPENGL_CREATE_JUCE_RENDER_THREAD not defined)

Cheers, Yair

(more info at http://www.juce.com/comment/309350#comment-309350)


#8

jni file not rebuild after removing all (.)dots . so can u suggest ushow rebuild jni.c file.