Material.setParam() with an ArrayList goes NULL in Uniform.setValue()?

Hi all, I’m trying to pass a small Vector3f ArrayList to a shader using an Uniform defined as arrPolygonShapeVertices. I understand there is a 1024 items hard limit on old graphics cards and I’m not even close to a fraction of it so it’s not the issue.

Using this code:

if(arrPolygonShapeVertices != null){
System.out.println("AAA: " + arrPolygonShapeVertices);
material.setParam(“arrPolygonShapeVertices”, VarType.Vector3Array, arrPolygonShapeVertices);
System.out.println("BBB: " + arrPolygonShapeVertices.size());
material.setInt(“polygonShapeVerticesLength”, arrPolygonShapeVertices.size());

… I’m getting this in the console:

AAA: [(-127.0, 158.08269, -127.0), (93.0, 163.52136, -127.0), (-39.0, 167.57544, -119.0), (59.0, 164.05804, -111.0), (-37.0, 148.2067, -87.0), (-91.0, 133.28836, -71.0)]
BBB: 6
mars 06, 2014 12:02:41 PM handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
at com.jme3.shader.Uniform.setValue(
at com.jme3.material.Technique.updateUniformParam(
at com.jme3.material.MatParam.apply(
at com.jme3.material.Material.render(
at com.jme3.renderer.RenderManager.renderGeometry(
at com.jme3.renderer.RenderManager.renderViewPort(
at com.jme3.renderer.RenderManager.render(
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(

The material file defines the uniform fine. The error message clearly states whenever you forget to define a uniform in the material file so this ain’t it either.

What makes it NULL by the time com.jme3.shader.Uniform.setValue( processes it? Not getting it :stuck_out_tongue:

As you can see in the error log, I’m running this off a thread that runs perfectly if I comment this part. I’m not sure if it’s related or not, I would assume that it’s not related tough.

Any ideas? Thx

I can’t see any paths through the code that would cause the value to go null.

However, ArrayList != array. So you will need to convert your ArrayList to an array in any case. This may or may not fix your problem if something else is wrong.

Hi Paul, thanks for replying. Well, yes I know they’re different types but at first I even had List<Vector3f> and it would not even complain about this. I decided to go with ArrayList<Vector3f> because I saw this working example that uses exactly the same type and same method as what I’m trying to do here:

On line #101 you can see the exact same way I’m trying:

this.material.setParam(“Collisions”, VarType.Vector3Array, collisionsArray);

… where collisionsArray is defined in the header as: private ArrayList<Vector3f> collisions;

So I mean… it’s exactly the same code, except for the variable name.

I will check again for another problem source (I was doing something else in the last few hours) because maybe it stops there but complains about something else being NULL.

EDIT: I just made a big mistake, I did not read their code correctly. collisionsArray is DEFINITELY a real array, I’m sorry, I did not read it carefully. OK I will try this way on my project, see if it makes a difference or not.

final Vector3f[] collisionsArray = new Vector3f[Math.min(this.collisions.size(), this.MAX_HITS)];
for (int i = 0; i < this.collisions.size() && i < this.MAX_HITS; i++) {
collisionsArray[i] = this.collisions.get(this.collisions.size() - 1 - i);
this.material.setParam(“Collisions”, VarType.Vector3Array, collisionsArray);

EDIT: Well, even after converting the ArrayList to a primitive Vector3f[] type, like the above code, it gives exactly the same error. I’m convinced now the NULL is something else triggered by this code tough, but I’ll do more testing and come back here. Thx

Yeah, I “cheated” and looked at the actual JME code… which only handles real arrays.

OK for future reference, I got it working and it was indeed something else that was causing this ambiguous NULL error. Thank you Paul also for letting me know I was using the wrong array type, this would not have worked without it either lol.

Case closed.