Hello everyone, I am programming a 3d terrain generator, and I use an array to store block information, and store the groups of 64x64x64 chunks to ease up on the processor demand. (Rendering 26 meshes of 64x64x64 pregenerated meshes is a lot easier than rendering 1 mesh of 4607442944 cubes)
So the problem is, when I start my engine up, and the chunk manager lays out 2x2x2 chunks, and there is a giant fissure between each chunk. When I say fissure, it means a complete absence of blocks on the outside of each chunk. This makes me think that something is wrong with the way my arrays are handled, however, when I try to use the arrays as proper C++ dictates, I get a SEGFAULT crash, which makes no sense. So the fix that leaves fissures is really ghetto and not proper.
Here's the code:
The chunk class:
#define CHUNK_SIZE 64
Chunk(int x,int y,int z,int id);
void Update(float delta);
void Render(Ogre::SceneManager* sceneManager);
void loadTerrain(terrainGenerator* terraGen);
And heres some of the implementation that causes problems:
void Chunk::Render(Ogre::SceneManager* sceneManager)
Ogre::ManualObject* MeshChunk = new Ogre::ManualObject("MeshManChunk" + Ogre::StringConverter::toString(m_ChunkID));
int iVertex = 0;
for (int z = 0; z < CHUNK_SIZE-1; z++)// + chunkPos
for (int y = 0; y < CHUNK_SIZE-1; y++)// + chunkPos
for (int x = 0; x < CHUNK_SIZE-1; x++)// + chunkPos
int px = x+chunkPos;//World Position
int py = y+chunkPos;
int pz = z+chunkPos;
Block = chunkBlocks[x][y][z]->isActive();//This crashes
Block1 = 0;
if (x-1 >= 0) Block1 = chunkBlocks[x-1][y][z]->isActive();//So does this
//Note the check to make sure that x-1 would not go out of bounds..
if (Block1 == 0)
//arbitrary render code that makes no use of the array
//The above block check repeats for each face..
I don't think I need to explain the complete implementation to solve the problem, unless someone wants me to in which case I will..but the problem is the for loop. The one above is the one that works, but shouldn't it be:
for (int z = 0; z <= CHUNK_SIZE; z++)
for (int y = 0; y <= CHUNK_SIZE; y++)
for (int x = 0; x <= CHUNK_SIZE; x++)
To loop through all the elements in the array? Cause this crashes.