Open cbarber opened 13 years ago
good catch, thanks. i think it would be faster to catch the exception, instead of checking path.isfile. I'll think about where the best place for that would be (either in nbt.py or in _load_left and _load_right of chunk.py). I'll push a fix tonight
Confirmed that everything worked after the fix is in place.
I would advise against using the exception for two reasons:
You could keep an array of tuples or a custom object to store which regions exist. Then you could check if you're going out of bounds before trying to load the region. No file system check or exception.
I'm new to github and git so I'm not sure what the best procedure for helping here is. Would you prefer unified patches or fork/pull request?
when i suggested to use exceptions, i didn't mean to add "if not file exists, throw exception", but simply try to open() the file, and if it doesn't exist, catch the the exception (either in _file_loader or somewhere higher up). I think this will be faster since this will probably be a rare occurrence, but this may be a debatable point.
interestingly, i haven't been able to reproduce this bug. i've tried rendering several maps, and all run to completion without throwing this exception. as far as i can tell, this will only happen when chunkX,chunkY is right on the edge of a region, and so chunk_path = self.world.get_region_path(self.chunkX - 1, self.chunkY) returns a region that doesn't exist. (note that if chuckX, chunkY is in the middle of a region, chunk_path will always reference a valid region)
anyway, since you've tested your patch, i'll gladly accept it. i can either apply your patch and commit it on your behalf, or you can submit a pull request. normally i like pull requests, but since this change is so minor, it'll probably be easier for me to just apply the patch manually (unless you wan't the experience of submitting a pull request)
I just ran into this same issue, just FYI
I am not a pythonista by any stretch, but I did give a shot at wrapping it in a try/except block and added in the logging module so I could see it happening. My output looks roughly like this:
2011-02-26 13:08:18,874 [INFO] 500/6144 chunks rendered 2011-02-26 13:12:04,570 [INFO] 1000/6144 chunks rendered 2011-02-26 13:12:14,323 [WARNING] Error Opening.../region/r.-2.-1.mcr 2011-02-26 13:12:14,332 [WARNING] Error Opening .../region/r.-2.-1.mcr ... 2011-02-26 13:19:22,155 [INFO] 2000/6144 chunks rendered
Patch: --- nbt.py.orig 2011-02-26 13:24:41.000000000 -0600 +++ nbt.py 2011-02-26 13:24:53.000000000 -0600 @@ -16,13 +16,18 @@ import gzip, zlib import struct import StringIO +import logging
# decorator to handle filename or object as first parameter
def _file_loader(func):
def wrapper(fileobj, *args):
if isinstance(fileobj, basestring):
# Is actually a filename
- fileobj = open(fileobj, 'rb')
+ try:
+ fileobj = open(fileobj, 'rb')
+ except Exception, e:
+ logging.warning("Error Opening %s, continuing..." % fileobj);
+ return None
return func(fileobj, *args)
return wrapper
Using the latest Beta 1.3 Minecraft server without mods and an upgraded McRegion world on FreeBSD 8.1-RELEASE.
I'm receiving an unhandled exception in nbt.py trying to open a region file that does not exist in my world directory. I believe this is caused by
when chunkX is negative.
IOError: [Errno 2] No such file or directory: '/home/cbarber/minecraft/world/region/r.-4.-2.mcr'
gmap.py output follows:
My fix was to check if the region file exists, otherwise return None, which should bubble up properly.
Currently running on 5000/31744 chunks so looks promising.