Optimization Bug? jme 2

Hi guys!



When you apply the following patch to the jme 2 project:


Index: src/jmetest/data/images/attributeshader.frag
===================================================================
--- src/jmetest/data/images/attributeshader.frag   (revision 5445)
+++ src/jmetest/data/images/attributeshader.frag   (working copy)
@@ -1,5 +1,5 @@
 
 void main(void)
 {
-    gl_FragColor = gl_Color;
+    gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
 }
No newline at end of file



and execute the TestGLSLShaderAttributes test you will get the following exception:


SEVERE: Shader attribute [vertexColors] could not be located in shader
Jul 16, 2010 1:33:57 PM class jmetest.renderer.state.TestGLSLShaderAttributes start()
SEVERE: Exception in game loop
java.lang.ArrayIndexOutOfBoundsException: -1
   at org.lwjgl.opengl.ARBVertexProgram.glVertexAttribPointerARB(ARBVertexProgram.java:176)
   at com.jme.scene.state.lwjgl.shader.LWJGLShaderUtil.updateShaderAttribute(LWJGLShaderUtil.java:249)
   at com.jme.scene.state.lwjgl.shader.LWJGLShaderUtil.updateShaderAttribute(LWJGLShaderUtil.java:233)
   at com.jme.scene.state.lwjgl.LWJGLShaderObjectsState.apply(LWJGLShaderObjectsState.java:341)
   at com.jme.renderer.lwjgl.LWJGLRenderer.applyStates(LWJGLRenderer.java:1743)
   at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:979)
   at com.jme.scene.TriMesh.draw(TriMesh.java:240)
   at com.jme.scene.Spatial.onDraw(Spatial.java:472)
   at com.jme.scene.Node.draw(Node.java:521)
   at com.jme.scene.Spatial.onDraw(Spatial.java:472)
   at com.jme.renderer.lwjgl.LWJGLRenderer.draw(LWJGLRenderer.java:1220)
   at com.jme.app.SimpleGame.render(SimpleGame.java:81)
   at com.jme.app.BaseGame.start(BaseGame.java:87)
   at jmetest.renderer.state.TestGLSLShaderAttributes.main(TestGLSLShaderAttributes.java:51)



which is very strange, since it's actually there. What happenes is that i don't use gl_Color int he fragment shader anymore, and thus the GLSL compiler seems to optimize everything away that I dont need, including the attributes in the vertex shader? Is this the reason? How can I solve this? Can I tell the GLSL compiler to please not optimize everything away?

Thanks to all the GLSL gurus out there that can help me here  ;)

Actually the correct thing to do in this case is ignore the attribute from within code, rather than throwing the exception.

perfect, I'll make a patch and contribute.