doesn't crash on a corrupt world chunk
This commit is contained in:
11
chunk.py
11
chunk.py
@@ -17,6 +17,7 @@ import numpy
|
|||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
import os.path
|
import os.path
|
||||||
import hashlib
|
import hashlib
|
||||||
|
import logging
|
||||||
|
|
||||||
import nbt
|
import nbt
|
||||||
import textures
|
import textures
|
||||||
@@ -91,6 +92,9 @@ def render_and_save(chunkfile, cachedir, cave=False):
|
|||||||
a = ChunkRenderer(chunkfile, cachedir)
|
a = ChunkRenderer(chunkfile, cachedir)
|
||||||
try:
|
try:
|
||||||
return a.render_and_save(cave)
|
return a.render_and_save(cave)
|
||||||
|
except ChunkCorrupt:
|
||||||
|
# This should be non-fatal, but should print a warning
|
||||||
|
pass
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
@@ -104,6 +108,9 @@ def render_and_save(chunkfile, cachedir, cave=False):
|
|||||||
# forever for it to finish.
|
# forever for it to finish.
|
||||||
raise Exception()
|
raise Exception()
|
||||||
|
|
||||||
|
class ChunkCorrupt(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
class ChunkRenderer(object):
|
class ChunkRenderer(object):
|
||||||
def __init__(self, chunkfile, cachedir):
|
def __init__(self, chunkfile, cachedir):
|
||||||
"""Make a new chunk renderer for the given chunkfile.
|
"""Make a new chunk renderer for the given chunkfile.
|
||||||
@@ -134,7 +141,11 @@ class ChunkRenderer(object):
|
|||||||
def _load_level(self):
|
def _load_level(self):
|
||||||
"""Loads and returns the level structure"""
|
"""Loads and returns the level structure"""
|
||||||
if not hasattr(self, "_level"):
|
if not hasattr(self, "_level"):
|
||||||
|
try:
|
||||||
self._level = get_lvldata(self.chunkfile)
|
self._level = get_lvldata(self.chunkfile)
|
||||||
|
except Exception, e:
|
||||||
|
logging.warning("Error opening chunk file %s. It may be corrupt. %s", self.chunkfile, e)
|
||||||
|
raise ChunkCorrupt(str(e))
|
||||||
return self._level
|
return self._level
|
||||||
level = property(_load_level)
|
level = property(_load_level)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user