If numpy has a problem reshaping data, issue a warning instead of crashing
Addresses #1038
This commit is contained in:
@@ -414,6 +414,7 @@ class RegionSet(object):
|
|||||||
|
|
||||||
# Turn the skylight array into a 16x16x16 matrix. The array comes
|
# Turn the skylight array into a 16x16x16 matrix. The array comes
|
||||||
# packed 2 elements per byte, so we need to expand it.
|
# packed 2 elements per byte, so we need to expand it.
|
||||||
|
try:
|
||||||
skylight = numpy.frombuffer(section['SkyLight'], dtype=numpy.uint8)
|
skylight = numpy.frombuffer(section['SkyLight'], dtype=numpy.uint8)
|
||||||
skylight = skylight.reshape((16,16,8))
|
skylight = skylight.reshape((16,16,8))
|
||||||
skylight_expanded = numpy.empty((16,16,16), dtype=numpy.uint8)
|
skylight_expanded = numpy.empty((16,16,16), dtype=numpy.uint8)
|
||||||
@@ -439,6 +440,13 @@ class RegionSet(object):
|
|||||||
data_expanded[:,:,1::2] = (data & 0xF0) >> 4
|
data_expanded[:,:,1::2] = (data & 0xF0) >> 4
|
||||||
del data
|
del data
|
||||||
section['Data'] = data_expanded
|
section['Data'] = data_expanded
|
||||||
|
except ValueError:
|
||||||
|
# iv'e seen at least 1 case where numpy raises a value error during the reshapes. i'm not
|
||||||
|
# sure what's going on here, but let's treat this as a corrupt chunk error
|
||||||
|
logging.warning("There was a problem reading chunk %d,%d. It might be corrupt. I am giving up and will not render this particular chunk.", x, z)
|
||||||
|
|
||||||
|
logging.debug("Full traceback:", exc_info=1)
|
||||||
|
raise nbt.CorruptChunkError()
|
||||||
|
|
||||||
return chunk_data
|
return chunk_data
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user