[SOLVED] Mesh class .copy() function error
3 posts
• Page 1 of 1
[SOLVED] Mesh class .copy() function error
Hi, I'm trying to use the Mesh.java copy() function and I'm getting a NullPointerException. I'm running libGDX ver. 1.9.6 and the LWJGL Desktop configuration. Below is the test code I used and error output. Following the function calls through the stack trace, it looks like the copy() function is passing a null reference to the setIndices() function of the IndexBufferObject class. The path of error flows from
1. call copy()
2. result.setIndices(indices);
where
and indices is
3. this.indices.setIndices(indices, 0, indices.length);
where
4. setIndices() throws an error because of 'null' value that 'indices' is holding.
Is this a bug or am I forgetting to initialize something? Thanks for any help.
1. call copy()
2. result.setIndices(indices);
where
- Code: Select all
result = new Mesh(isStatic, numVertices, indices == null ? 0 : indices.length, attrs)
and indices is
- Code: Select all
short[] indices = null;
3. this.indices.setIndices(indices, 0, indices.length);
where
- Code: Select all
this.indices = IndexBufferObject(isStatic, maxIndices);
4. setIndices() throws an error because of 'null' value that 'indices' is holding.
Is this a bug or am I forgetting to initialize something? Thanks for any help.
- Code: Select all
public class MyMeshTest extends ApplicationAdapter{
ModelInstance modelInstance;
private ModelBatch modelBatch;
private Camera camera;
@Override
public void create () {
//pass in '0' for numIndices because I don't want to index the Mesh
Mesh m = new Mesh(false, 3, 0, new VertexAttribute( VertexAttributes.Usage.Position, 3, "3_vec" ));
m.setVertices(new float[]{1,2,3, 2,3,4, 3,3,9});
//m.setIndices(new short[]{});
m.copy(false);
}
@Override
public void render () {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
}
@Override
public void dispose () {
modelBatch.dispose();
}
}
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.badlogic.gdx.graphics.Mesh.setIndices(Mesh.java:271)
at com.badlogic.gdx.graphics.Mesh.copy(Mesh.java:1084)
at com.badlogic.gdx.graphics.Mesh.copy(Mesh.java:1092)
at com.mygdx.meshtest.MyMeshTest.create(MyMeshTest.java:40)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:149)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:126)
Last edited by libbyjix on Mon Jun 26, 2017 8:13 am, edited 1 time in total.
- libbyjix
- Posts: 18
- Joined: Fri May 15, 2015 5:07 pm
Re: Mesh class .copy() function error
It's a bug in Mesh.copy(). It tries to pass null to setIndices() if copying a Mesh with 0 indices. You should open an issue
- tenfour04
- Posts: 1235
- Joined: Sat Jun 18, 2011 10:24 am
Re: Mesh class .copy() function error
Ok, will do. Just wanted to make sure I wasn't overlooking something obvious before jumping straight to assuming it was a bug. Thanks
- libbyjix
- Posts: 18
- Joined: Fri May 15, 2015 5:07 pm
3 posts
• Page 1 of 1
Return to Libgdx