uniform and nullPointerException

Started by Thomas., June 21, 2012, 12:17:35 PM

Previous topic - Next topic

Thomas.

When I call shader.setUniform("lightDirection", new SimpleVector(0, 0, 1)); I'll get this error, any idea where is problem?

06-21 12:10:37.432: E/AndroidRuntime(16226): FATAL EXCEPTION: GLThread 2166
06-21 12:10:37.432: E/AndroidRuntime(16226): java.lang.RuntimeException: [ 1340273437379 ] - ERROR: java.lang.NullPointerException
06-21 12:10:37.432: E/AndroidRuntime(16226): at com.threed.jpct.GLSLShader.update(GLSLShader.java:561)
06-21 12:10:37.432: E/AndroidRuntime(16226): at com.threed.jpct.GL20.updateShaderData(GL20.java:215)
06-21 12:10:37.432: E/AndroidRuntime(16226): at com.threed.jpct.GLRenderer.initShader(GLRenderer.java:519)
06-21 12:10:37.432: E/AndroidRuntime(16226): at com.threed.jpct.CompiledInstance.render(CompiledInstance.java:431)
06-21 12:10:37.432: E/AndroidRuntime(16226): at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2211)
06-21 12:10:37.432: E/AndroidRuntime(16226): at com.threed.jpct.World.draw(World.java:1319)
06-21 12:10:37.432: E/AndroidRuntime(16226): at com.threed.jpct.World.draw(World.java:1081)
06-21 12:10:37.432: E/AndroidRuntime(16226): at cz.chladek.mygame.AppActivity$MyRenderer.onDrawFrame(AppActivity.java:555)
06-21 12:10:37.432: E/AndroidRuntime(16226): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463)
06-21 12:10:37.432: E/AndroidRuntime(16226): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)
06-21 12:10:37.432: E/AndroidRuntime(16226): at com.threed.jpct.Logger.log(Logger.java:189)
06-21 12:10:37.432: E/AndroidRuntime(16226): at com.threed.jpct.Logger.log(Logger.java:148)
06-21 12:10:37.432: E/AndroidRuntime(16226): at cz.chladek.mygame.AppActivity$MyRenderer.onDrawFrame(AppActivity.java:625)
06-21 12:10:37.432: E/AndroidRuntime(16226): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463)
06-21 12:10:37.432: E/AndroidRuntime(16226): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)


And could you add method setUniform(String name, SimpleVector[] vals)? Thanks

EgonOlsen

I'm not sure about this error...the only reason that i can imagine is that you use the same name twice for another type of uniform...most likely a matrix. Could you please check this!?

I'll look into that SimpleVector[] thing...

EgonOlsen

I've added methods to set SimpleVector[] uniforms, but they are 100% untested. Please give it a try: http://jpct.de/download/beta/jpct_ae.jar

Thomas.

#3
In shader is just one uniform. I get NullPointerException just when I want calculate with it. (uniform is in spot light but also in point light and is update every frame). And thanks for update :)

uniform highp vec3 lightDirection;

EDIT: SimpleVector[] working, SimpleVector not...

EgonOlsen


EgonOlsen

Could you please post the exception's stack trace again when using the new version!?

Thomas.

Here is it...

06-21 22:35:27.906: E/AndroidRuntime(3377): FATAL EXCEPTION: GLThread 5196
06-21 22:35:27.906: E/AndroidRuntime(3377): java.lang.RuntimeException: [ 1340310927866 ] - ERROR: java.lang.NullPointerException
06-21 22:35:27.906: E/AndroidRuntime(3377): at com.threed.jpct.GLSLShader.update(GLSLShader.java:589)
06-21 22:35:27.906: E/AndroidRuntime(3377): at com.threed.jpct.GL20.updateShaderData(GL20.java:215)
06-21 22:35:27.906: E/AndroidRuntime(3377): at com.threed.jpct.GLRenderer.initShader(GLRenderer.java:519)
06-21 22:35:27.906: E/AndroidRuntime(3377): at com.threed.jpct.CompiledInstance.render(CompiledInstance.java:431)
06-21 22:35:27.906: E/AndroidRuntime(3377): at com.threed.jpct.GLRenderer.drawVertexArray(GLRenderer.java:2211)
06-21 22:35:27.906: E/AndroidRuntime(3377): at com.threed.jpct.World.draw(World.java:1319)
06-21 22:35:27.906: E/AndroidRuntime(3377): at com.threed.jpct.World.draw(World.java:1081)
06-21 22:35:27.906: E/AndroidRuntime(3377): at cz.chladek.mygame.AppActivity$MyRenderer.onDrawFrame(AppActivity.java:554)
06-21 22:35:27.906: E/AndroidRuntime(3377): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463)
06-21 22:35:27.906: E/AndroidRuntime(3377): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)
06-21 22:35:27.906: E/AndroidRuntime(3377): at com.threed.jpct.Logger.log(Logger.java:189)
06-21 22:35:27.906: E/AndroidRuntime(3377): at com.threed.jpct.Logger.log(Logger.java:148)
06-21 22:35:27.906: E/AndroidRuntime(3377): at cz.chladek.mygame.AppActivity$MyRenderer.onDrawFrame(AppActivity.java:624)
06-21 22:35:27.906: E/AndroidRuntime(3377): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463)
06-21 22:35:27.906: E/AndroidRuntime(3377): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)

EgonOlsen

Please download the jar again. It should be fixed now...what a stupid mistake (no, i'm not gonna tell you what it was... ;)).

Thomas.

Yes, it's fixed :) ... everyone makes mistakes, with so much complexity of engine is not surprising ;)

Thomas.

Something strange... before I used "const lowp float spotExp = 30;" and it was OK, but now I change this one to uniform and lighting is bad (seems like much higher spotExp)... where could be wrong?

EgonOlsen

Make sure that you set floats as floats, i.e. do

setUniform("blah", 3.0f), not setUniform("blah", 3). because that will use the int-value-version of the method.

Thomas.

I set 30f in constructor of light and to uniform is sended float array, but problem is same also with "shader.setUniform("spotExp", 30.0f);"

EgonOlsen

Then i don't know. I wonder why it compiled in the first place, because glsl actually doesn't allow for defining a float as 30;. At least my phone gives compiler errors if i don't type 30.0;

What's the exact line you are using now to define the uniform and does using a higher precision helps?

Thomas.

Oh sorry, before it was 30.0, you are right, with 30 I'll get errors.

Now I tried this = bad lighting... value in LogCat is 30.0... low and high precision
exponents[0] = 30.0f;
shader.setUniform("spotExp", exponents);
Logger.log("e" + exponents[0]);


same result with lowp, mediump and highp = good lighting
const lowp float spotExp= 30.0;

lighting with low precision = bad... but with high is fine... but I need array... phone is doing kidding me??
shader.setUniform("spotExp", 30.0f);

EgonOlsen

What's the length of "exponents" then?