Author Topic: uniform and nullPointerException  (Read 4006 times)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
uniform and nullPointerException
« on: June 21, 2012, 12:17:35 pm »
When I call shader.setUniform("lightDirection", new SimpleVector(0, 0, 1)); I'll get this error, any idea where is problem?

Code: [Select]
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

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: uniform and nullPointerException
« Reply #1 on: June 21, 2012, 09:52:36 pm »
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...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: uniform and nullPointerException
« Reply #2 on: June 21, 2012, 10:10:37 pm »
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

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: uniform and nullPointerException
« Reply #3 on: June 21, 2012, 10:19:35 pm »
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 :)

Code: [Select]
uniform highp vec3 lightDirection;
EDIT: SimpleVector[] working, SimpleVector not...
« Last Edit: June 21, 2012, 10:24:06 pm by Thomas. »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: uniform and nullPointerException
« Reply #4 on: June 21, 2012, 10:27:11 pm »
I'll look at it again...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: uniform and nullPointerException
« Reply #5 on: June 21, 2012, 10:29:26 pm »
Could you please post the exception's stack trace again when using the new version!?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: uniform and nullPointerException
« Reply #6 on: June 21, 2012, 10:36:21 pm »
Here is it...

Code: [Select]
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)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: uniform and nullPointerException
« Reply #7 on: June 21, 2012, 10:39:53 pm »
Please download the jar again. It should be fixed now...what a stupid mistake (no, i'm not gonna tell you what it was... ;)).

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: uniform and nullPointerException
« Reply #8 on: June 21, 2012, 10:51:52 pm »
Yes, it's fixed :) ... everyone makes mistakes, with so much complexity of engine is not surprising ;)

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: uniform and nullPointerException
« Reply #9 on: June 21, 2012, 11:05:44 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: uniform and nullPointerException
« Reply #10 on: June 21, 2012, 11:12:30 pm »
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.

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: uniform and nullPointerException
« Reply #11 on: June 21, 2012, 11:19:52 pm »
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);"

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: uniform and nullPointerException
« Reply #12 on: June 21, 2012, 11:30:34 pm »
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?

Offline Thomas.

  • double
  • *****
  • Posts: 833
    • View Profile
Re: uniform and nullPointerException
« Reply #13 on: June 21, 2012, 11:59:13 pm »
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
Code: [Select]
exponents[0] = 30.0f;
shader.setUniform("spotExp", exponents);
Logger.log("e" + exponents[0]);

same result with lowp, mediump and highp = good lighting
Code: [Select]
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??
Code: [Select]
shader.setUniform("spotExp", 30.0f);

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11747
    • View Profile
    • http://www.jpct.net
Re: uniform and nullPointerException
« Reply #14 on: June 22, 2012, 12:05:09 am »
What's the length of "exponents" then?