[libgdx]Mesh.setVertices(short[] indices,offset, count) behavior on android

I have a dynamic mesh, so every frame I must update the vertices and indices.
I populate a FloatArray with the new vertices and then when flushing the array, if I call


mesh.setVertices(finalMesh.array());

everything works fine, however there’s a performance hit since my finalMesh float buffer can vary in size and I don’t want to flush the whole array everytime.

So I tried doing a


mesh.setVertices(finalMesh.array(), 0, finalMesh.position());

Which works ok on my desktop.
However on Android However in some other computers/devices with this setup, it shows a lot of garbage on the screen.
I tested with my Mac (no problems), Android Moto G (problems) and windows (problems)

Any ideas on how to avoid that ? Or it’s the safest bet just to flush the whole array every frame?

depends on what [icode]setVertices()[/icode] does. how does the code look like ?

Well that’s a libgdx method.

I’m just speculating here, buy maybe you can use

mesh.updateVertices

to avoid resizing the backing buffer and just update the vertices you need to update.

Then when you render, use this method in the Mesh class:

	public void render (ShaderProgram shader, int primitiveType, int offset, int count) {
		render(shader, primitiveType, offset, count, autoBind);
	}

and you should be able to only render the portion you are using.

I think I have played with this before, but didn’t get it working and ended up just using setVertices, which worked for me since I didn’t need to use it every frame anyways.

aah, sorry for my ignorance - i’m not using libgdx.

looking at that code it looks like the error is hidden in the input arguments.

when the first method is just a shortcut for [icode](array, 0, array.length)[/icode] and you get a different behaviour from passing [icode]finalMesh.position()[/icode] i bet you can solve it simply by debugging this values.

also as jrenner said, using [icode]updateVertices[/icode] sounds like a reasonable method. but again, i never used gdx, sorry.