Infinite terrain generation algorithm problems

Notice: This question is long winded, and anyone wanting to help will need to dig through a formidable amount of code looking for an obscure glitch. If you are faint of heart, please turn away now.

I had asked a question that is more or less identical to this one a few months ago, but lacking a sufficiant answer and unable to find an answer myself after several months of on and off trying, I am here to ask for help again.

I am making infinite terrain generation, and have come across a problem. It is block and chunk based (think Minecraft), and it is supposed to make a mesh for each chunk by putting adding 2 triangles for every face of a block that is facing air. However, it does not do this correctly, and oftentimes renders blocks that are surrounded by other solid blocks. The only pattern I see in the rendering error are as follows:

  • If the player shifts positively in the x-axis to prompt new chunks to be loaded, extra blocks seem to be loaded below the player with the quantity equal to how many chunks the player shifted.
  • If the player shifts negatively in the x-axis, no blocks are rendered.

Any help would be appreciated.

I have used the following link as a guide to the scripts, reading through it may help you understand how my code works.
Guide

Below I have the links to the different files in the generation (in descending order of importance)

ChunkRenderer.cs
World.cs
terrainGen.cs
Chunk.cs
B.cs
BlockTypes.cs
DirtyType.cs
AirType.cs
PriorityQueue.cs

Also, the website of unity answers seems to have a long running feud with me, and as such I often am unable to perform certain actions in posts, such as replying to answers. Because of this, I may post answers to this question that are really just replies to their answers, so please refrain from having the mistaken notion that I am making tons of new answers because I don’t know how the site works or that I’m just an asshat.

Ok, so I’ve finally fixed the error. Turns out the values of the chunk.blocks array was wrong, due to the makeChunk method failing to assign the values of the blocks before it rendered the chunk, since the chunks blocks are only assigned after the method returns, while the chunk renderer needs them to be assigned before they return. I just changed the method from this:

Chunk makeChunk(World world, int cx, int cy, int cz, Texture2D texture)
{
Vector3 chunkAssignPos = new Vector3();
Chunk chunk = assignChunk(cx, cy, cz, ref chunkAssignPos, true);
ChunkRenderer.render(world, ref chunk, cx, cy, cz, texture, chunkAssignPos);
return chunk;
}

into this:

void makeChunk(World world, ref Chunk chunk, int cx, int cy, int cz, Texture2D texture)
{
Vector3 chunkAssignPos = new Vector3();
chunk = assignChunk(cx, cy, cz, ref chunkAssignPos, true);
ChunkRenderer.render(world, ref chunk, cx, cy, cz, texture, chunkAssignPos);
}

And now it works. Thanks to everyone for trying to help. Wow, it took what, 4 months working on and off to find this? I must be the worst debugger ever. XD