Android OpenGL error: “remaining() < needed” and Android 4.4

纵然是瞬间 提交于 2019-12-29 09:42:10

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/21941756/android-opengl-error-remaining-needed-and-android-4-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!