java - Fatal error running OpenGL ES 2 program on Android device, but not on the emulator -
i developing breakout-style game on android using opengl es 2.0 , i've run fatal error happens on android device (version 2.3.4) doesn't happen on emulator (android version 5.0.1). first thought bug difference of versions i'm not entirely convinced.
i had game working nicely on both emulator , device, problem occurred when wanted add particle effect shader, , received runtime exception during compilation of second shader seen in stack trace below.
03-31 15:50:52.339 24359-24371/com.package e/glslprogram class﹕ glattachshader: glerror 1281 03-31 15:50:52.359 24359-24371/com.package w/dalvikvm﹕ threadid=9: thread exiting uncaught exception (group=0x40018560) 03-31 15:50:52.359 24359-24371/com.package e/androidruntime﹕ fatal exception: glthread 10 java.lang.runtimeexception: glattachshader: glerror 1281 @ com.package.glslprogram.checkglerror(glslprogram.java:55) @ com.package.glslprogram.<init>(glslprogram.java:38) @ com.package.resourcemanager.insertshader(resourcemanager.java:103) @ com.package.gamerenderer.onsurfacecreated(gamerenderer.java:69) @ android.opengl.glsurfaceview$glthread.guardedrun(glsurfaceview.java:1349) @ android.opengl.glsurfaceview$glthread.run(glsurfaceview.java:1119) 03-31 15:50:52.369 24359-24359/com.package d/gameactivity﹕ in onpause 03-31 15:50:52.729 24359-24359/com.package e/libegl﹕ call opengl es api no current context (logged once per thread)
i have method android opengl es 2 tutorial call after many opengl method calls (notably ones don't want cause problems):
public static void checkglerror(string gloperation) { int error; while ((error = gles20.glgeterror()) != gles20.gl_no_error) { log.e(tag, gloperation + ": glerror " + error); throw new runtimeexception(gloperation + ": glerror " + error); } }
i notice stack trace says error occurs after shader compilation (glattachshader). if comment out checkglerror function program won't crash particle effect i'm trying create won't show means shader didn't compile. thus, assume issue particle vertex , fragment shaders compile , run expected on emulator. here particle vertex , fragment shaders:
vertex:
attribute vec4 avertex; // vec2 position, vec2 tex coords varying vec2 vtexcoords; varying vec4 vparticlecolor; uniform mat4 uparticleprojection; uniform vec2 uparticleoffset; uniform vec4 uparticlecolor; void main() { float scale = 10.0f; vtexcoords = avertex.zw; vparticlecolor = uparticlecolor; gl_position = uparticleprojection * vec4((avertex.xy * scale) + uparticleoffset, 0.0, 1.0); }
fragment:
precision mediump float; varying vec2 vtexcoords; varying vec4 vparticlecolor; uniform sampler2d uparticle; void main() { gl_fragcolor = vparticlecolor * texture2d(uparticle, vtexcoords); }
i have opengl es 2 feature enabled in manifest. mentioned app runs fine on device until introduced particle shader. fact continues run on emulator has me baffled. figure version of device or shaders can't figure out.
is this function exposed in java opengl api? if can compile log driver , find out why doesn't compile.
at guess though:
float scale = 10.0f; // should -> float scale = 10.0; precision mediump float; // should in vertex shader also?
adding log function give more work rather guess.
Comments
Post a Comment