www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: Thomas. on June 21, 2012, 12:17:35 pm

Title: uniform and nullPointerException
Post by: Thomas. 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
Title: Re: uniform and nullPointerException
Post by: EgonOlsen 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...
Title: Re: uniform and nullPointerException
Post by: EgonOlsen 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 (http://jpct.de/download/beta/jpct_ae.jar)
Title: Re: uniform and nullPointerException
Post by: Thomas. 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...
Title: Re: uniform and nullPointerException
Post by: EgonOlsen on June 21, 2012, 10:27:11 pm
I'll look at it again...
Title: Re: uniform and nullPointerException
Post by: EgonOlsen on June 21, 2012, 10:29:26 pm
Could you please post the exception's stack trace again when using the new version!?
Title: Re: uniform and nullPointerException
Post by: Thomas. 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)
Title: Re: uniform and nullPointerException
Post by: EgonOlsen 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... ;)).
Title: Re: uniform and nullPointerException
Post by: Thomas. on June 21, 2012, 10:51:52 pm
Yes, it's fixed :) ... everyone makes mistakes, with so much complexity of engine is not surprising ;)
Title: Re: uniform and nullPointerException
Post by: Thomas. 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?
Title: Re: uniform and nullPointerException
Post by: EgonOlsen 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.
Title: Re: uniform and nullPointerException
Post by: Thomas. 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);"
Title: Re: uniform and nullPointerException
Post by: EgonOlsen 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?
Title: Re: uniform and nullPointerException
Post by: Thomas. 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);
Title: Re: uniform and nullPointerException
Post by: EgonOlsen on June 22, 2012, 12:05:09 am
What's the length of "exponents" then?
Title: Re: uniform and nullPointerException
Post by: Thomas. on June 22, 2012, 12:08:42 am
app
Code: [Select]
exponents = new float[8];shader
Code: [Select]
uniform highp float spotExp[8];
Title: Re: uniform and nullPointerException
Post by: EgonOlsen on June 22, 2012, 12:12:32 am
I see...as the docs state, float[] is only supported for 1-4 elements ATM. I can remove this limitation, but it won't happen until the weekend. As a workaround until then, you can enlarge the array to 9 elements and store the values in the components of 3 SimpleVectors...yes, that's cludgy...but it should work.
Title: Re: uniform and nullPointerException
Post by: Thomas. on June 22, 2012, 12:22:51 am
Oh, this limitation has somehow escaped me... I'll wait for her removed (8 per-pixel spot lights are not important for me and for my phone :) ), and thanks for your help :)

EDIT: hmm, array length 1 working, but 2 not...
Title: Re: uniform and nullPointerException
Post by: EgonOlsen on June 22, 2012, 06:24:28 am
Maybe there's another problem with float-arrays...i'll look into it tomorrow.
Title: Re: uniform and nullPointerException
Post by: EgonOlsen on June 22, 2012, 01:46:44 pm
At least i found the reason for the problem with float[] to set a float[] uniform in the shader...it's not meant for that purpose, albeit the docs somehow suggest that it might be. These setters are actually to fill a float, vec2, vec or vec4 with the float[]-array's data. To set an actual float[], another method will be needed. I'll add it tomorrow.
Title: Re: uniform and nullPointerException
Post by: EgonOlsen on June 23, 2012, 01:46:29 pm
I've updated the jar and added a method called setFloatArrayUniform(...). Again, this is untested and i coded it while being forced to listen to children songs...so bear with me, if it's just an epic fail...
Title: Re: uniform and nullPointerException
Post by: Thomas. on June 23, 2012, 07:25:09 pm
I believe it must have been sheer torture :) But everything seems to be fine ;)