tomsrobots
tomsrobots

Reputation: 317

Android OpenGL error: "remaining() < needed" and Android 4.4

I am getting an error I do not understand when I try and launch my app on a phone running Android 4.4 (It's a Moto G if this helps):

java.lang.IllegalArgumentException: remaining() < needed

Exception thrown in Thread[GLThread 85832,5,main] java.lang.IllegalArgumentException: remaining < needed
at android.opengl.GLES20.glGetInteger v(Native Method)
at com.jme3.renderer.android.OGLESShaderRenderer.intialize(OGLESShaderRenderer.java:311)
at com.jme3.system.android.OGLESContext.initInThread(OGLESContext.java:215)
at com.jme3.system.android.OGLESContext.onSurfaceCreated(OGLESContext.java:187)
at android.opengl.GLSurfaceView$GLTread.guardedRun(GLSurfaceView.java:1501)
at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)

When I run the exact same code on an Xperia U running Android 4.0 it runs fine. What is going on here, and what steps can I take to make sure my code runs on a variety of devices?

Upvotes: 0

Views: 984

Answers (1)

fadden
fadden

Reputation: 52323

One variant of the glGetIntegerv() Java bindings takes an IntBuffer argument to hold multiple return values. If your request requires more space than the buffer holds, you will get this error.

Older versions of jMonkeyEngine did a request for GL_COMPRESSED_TEXTURE_FORMATS with a fixed-size buffer. The call failed on devices that supported too many formats. (You're supposed to query GL_NUM_COMPRESSED_TEXTURE_FORMATS, and use that value to size your buffer.) On older versions of Android this actually caused heap corruption, because the Java-language bindings did the comparison wrong and allowed the data to write past the end of the IntBuffer (fixed).

You can see the fix to jMonkeyEngine applied here. Judging by the line number in the exception, you're using a version of jMonkeyEngine that pre-dates the fix.

Upvotes: 1

Related Questions