diff options
author | Campbell Barton <ideasman42@gmail.com> | 2011-12-10 05:01:22 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2011-12-10 05:01:22 +0400 |
commit | 87ff925d909f75d2eb63ced6610c81f0b59c1fef (patch) | |
tree | a8156a4c2a3b705d033c3487dcbcab7fce60f082 /release/scripts/modules/bpy_extras | |
parent | 82b9e4d16f08e8ca1b3fee84226334b3012aaed3 (diff) |
fix for error in bpy_extras.image_utils.load_image() when the image file exists but cant be read (wrong permissions for eg).
Diffstat (limited to 'release/scripts/modules/bpy_extras')
-rw-r--r-- | release/scripts/modules/bpy_extras/image_utils.py | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/release/scripts/modules/bpy_extras/image_utils.py b/release/scripts/modules/bpy_extras/image_utils.py index 6d02b2b7af9..7d409510c85 100644 --- a/release/scripts/modules/bpy_extras/image_utils.py +++ b/release/scripts/modules/bpy_extras/image_utils.py @@ -65,19 +65,45 @@ def load_image(imagepath, # TODO: recursive + # ------------------------------------------------------------------------- + # Utility Functions + + def _image_load_placeholder(path): + name = bpy.path.basename(path) + if type(name) == bytes: + name = name.decode('utf-8', "replace") + image = bpy.data.images.new(name, 128, 128) + # allow the path to be resolved later + image.filepath = path + image.source = 'FILE' + return image + def _image_load(path): import bpy if convert_callback: path = convert_callback(path) - image = bpy.data.images.load(path) + try: + image = bpy.data.images.load(path) + except RuntimeError: + image = None if verbose: - print(" image loaded '%s'" % path) + if image: + print(" image loaded '%s'" % path) + else: + print(" image load failed '%s'" % path) + + # image path has been checked so the path could not be read for some + # reason, so be sure to return a placeholder + if place_holder: + image = _image_load_placeholder(path) return image + # ------------------------------------------------------------------------- + if verbose: print("load_image('%s', '%s', ...)" % (imagepath, dirname)) @@ -103,14 +129,9 @@ def load_image(imagepath, if os.path.exists(nfilepath): return _image_load(nfilepath) + # None of the paths exist so return placeholder if place_holder: - name = bpy.path.basename(imagepath) - if type(name) == bytes: - name = name.decode('utf-8', "replace") - image = bpy.data.images.new(name, 128, 128) - # allow the path to be resolved later - image.filepath = imagepath - return image + return _image_load_placeholder(imagepath) # TODO comprehensiveImageLoad also searched in bpy.config.textureDir return None |