rvandoosselaer / Blocks

A block (voxel) engine for jMonkeyEngine
BSD 3-Clause "New" or "Revised" License
42 stars 14 forks source link

NPE when generating a chunk #24

Open rvandoosselaer opened 4 years ago

rvandoosselaer commented 4 years ago

When using the ChunkPager it happened once that a Chunk was evicted from the ChunkCache while the ChunkManager was still generating the mesh.

This resulted in a NPE in the Chunk class:

public Block getBlock(int x, int y, int z) {
    if (isInsideChunk(x, y, z)) {
        return this.blocks[calculateIndex(x, y, z)];
    }
    ...

the this.blocks variable is null when the chunk is cleaned up.

This doesn't break the functionality since the ChunkPager decided that the chunk should not be rendered (hence the evict). But there is probably a better way to handle this behaviour. All tasks for chunks that are discarded should be aborted.