From f5f572a92bf387f5f6cb1a22199063cd4a67afd9 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Sat, 25 Sep 2010 23:10:49 -0400 Subject: [PATCH] fixed corrupt chunk handling code. Instead of re-gening the chunk, it now removes it and leaves it alone. The reason is that, now that the cache dir is separated from the chunk data files, there's no way for that code to know where it came from. For now, it's easier to just omit that one chunk, it'll be re-generated on the next run anyways. --- quadtree.py | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/quadtree.py b/quadtree.py index 10216b3..8aaf8b4 100644 --- a/quadtree.py +++ b/quadtree.py @@ -534,19 +534,27 @@ def render_worldtile(chunks, colstart, colend, rowstart, rowend, path): chunkimg = Image.open(chunkfile) chunkimg.load() except IOError, e: + # If for some reason the chunk failed to load (perhaps a previous + # run was canceled and the file was only written half way, + # corrupting it), then this could error. + # Since we have no easy way of determining how this chunk was + # generated, we need to just ignore it. print "Error opening file", chunkfile - print "Attempting to re-generate it..." - os.unlink(chunkfile) - # Do some string manipulation to determine what the chunk file is - # that goes with this image. Then call chunk.render_and_save - dirname, imagename = os.path.split(chunkfile) - parts = imagename.split(".") - datafile = "c.{0}.{1}.dat".format(parts[1],parts[2]) - #print "Chunk came from data file", datafile - # XXX Don't forget to set cave mode here when it gets implemented! - chunk.render_and_save(os.path.join(dirname, datafile), False) - chunkimg = Image.open(chunkfile) - print "Success" + try: + # Remove the file so that the next run will re-generate it. + os.unlink(chunkfile) + except OSError, e: + import errno + # Ignore if file doesn't exist, another task could have already + # removed it. + if e.errno != errno.ENOENT: + print "Could not remove the corrupt chunk!" + raise + else: + print "Removed the corrupt file" + + print "You will need to re-run the Overviewer to fix this chunk" + continue xpos = -192 + (col-colstart)*192 ypos = -96 + (row-rowstart)*96