reduce 'corrupted block detected ...' spam if chunk data is corrupted

This commit is contained in:
MihailRis 2024-12-11 15:23:16 +03:00
parent cfc16679cb
commit 91fa2838d6

View File

@ -40,13 +40,23 @@ void ChunksStorage::remove(int x, int z) {
} }
static void check_voxels(const ContentIndices& indices, Chunk* chunk) { static void check_voxels(const ContentIndices& indices, Chunk* chunk) {
bool corrupted = false;
for (size_t i = 0; i < CHUNK_VOL; i++) { for (size_t i = 0; i < CHUNK_VOL; i++) {
blockid_t id = chunk->voxels[i].id; blockid_t id = chunk->voxels[i].id;
if (indices.blocks.get(id) == nullptr) { if (indices.blocks.get(id) == nullptr) {
auto logline = logger.error(); if (!corrupted) {
logline << "corruped block detected at " << i << " of chunk "; #ifdef NDEBUG
logline << chunk->x << "x" << chunk->z; // release
logline << " -> " << id; auto logline = logger.error();
logline << "corruped blocks detected at " << i << " of chunk ";
logline << chunk->x << "x" << chunk->z;
logline << " -> " << id;
corrupted = true;
#else
// debug
abort();
#endif
}
chunk->voxels[i].id = BLOCK_AIR; chunk->voxels[i].id = BLOCK_AIR;
} }
} }