From ad0899bb8a8829480347e2877b40fc15ea50a1b5 Mon Sep 17 00:00:00 2001 From: Aaron Griffith Date: Thu, 17 Mar 2011 21:37:39 -0400 Subject: [PATCH] handle bad biome files on load, instead of waiting for an IndexError later related to --- textures.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/textures.py b/textures.py index fd199e4..f19c5c3 100644 --- a/textures.py +++ b/textures.py @@ -878,14 +878,17 @@ def getBiomeData(worlddir, chunkX, chunkY): if biomeFile == currentBiomeFile: return currentBiomeData - currentBiomeFile = biomeFile - f = open(os.path.join(worlddir, "biomes", biomeFile), "rb") rawdata = f.read() f.close() - + + # make sure the file size is correct + if not len(rawdata) == 512 * 512 * 2: + raise Exception("Biome file %s is not valid." % (biomeFile,)) + data = numpy.frombuffer(rawdata, dtype=numpy.dtype(">u2")) + currentBiomeFile = biomeFile currentBiomeData = data return data