Length out of range of buffer

Hello!
In my haphazard adventures in coding a voxel game, I have hit an unusual error. Since I am developing on mobile, I cannot see where the error here is. In game.js from lines 67-70 is the possible issue, though I was just working on generating indicies when it popped up. If someone knows the issue, any help is appreciated. Also. If you guys see any possible changes that should be made, make a suggestion!

Thank you.

Project:
https://playcanvas.com/editor/scene/1439135

Hi @Kurios,

I think the issue is your data set that you use to create the mesh is empty (positions, indices, UVs):

I’ve added a breakpoint in your code and I can verify that.

Try filling them with values before attempting to create a new mesh. You can check the mesh generation examples here:

https://playcanvas.github.io/#/graphics/mesh-generation

Thank you for responding @Leonidas!

However, I do not see exactly how this is going wrong. If you mean for me to not include the update, the vertex format breaks. Surprisingly, I was actually using the example you provided as the framework for me making this code! Could you give a direct edit suggestion on what I need to change? I’m afraid that my lack of experience puts me at a disadvantage in rooting out the issue.

I looked at the code closer and noticed a bigger issue… somehow the variables verts, norms, etc. are not being filled at all, not even in the function itself. If you look at the generateChunk() function, they are defined and filled with the push() method! Or should be.

What am I missing?

Adding a break point where you push values to the verts/norms etc show that that code is not being executed

Looking at the code here:

var block = blocks[i];
if(block != 0){

i is always 0 because you don’t increment it unless blocks[i] is not 0 which is not going to happen :sweat_smile:

Is this a typo?

1 Like

Oh wow, that was dumb of me. I fixed it now! And, the mesh displays, but very oddly. I will be able to fix it now that I can see it visually. Thank you for your help!

1 Like

I do not mean to annoy you, but if you look at the code again, and the image of the generated mesh, you will see something odd. I think I am connecting the vertices wrong, but I do not see how. Also, I do not see multiple chunks, as there should be at least 4 there.

Thank you for your patience.

Ah, when it comes to mesh generation, I’m afraid I know very little.

I would suggest creating a new project that just creates one or two chunks to make it easier for other users to investigate

I would recommend starting small.

  1. Make a quad from 2 triangles. Make sure it renders correctly
  2. Once done, extend it by adding another quad to it, so it forms a strip of 4 triangles.
  3. Once there, refactor your loop, so you could add variable amount of quads. Say, you input 10 and it will create a strip of 20 triangles.
  4. Once there, modify your verts positions loop to use perlin noise or what logic you have there for a small section of your mesh.
  5. Once that is ok, extend it for full size mesh.
1 Like