浏览代码

throw error when failed to load image

nagadomi 10 年之前
父节点
当前提交
1cdceb1648
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      lib/image_loader.lua

+ 6 - 0
lib/image_loader.lua

@@ -45,12 +45,18 @@ function image_loader.decode_byte(blob)
 end
 end
 function image_loader.load_float(file)
 function image_loader.load_float(file)
    local fp = io.open(file, "rb")
    local fp = io.open(file, "rb")
+   if not fp then
+      error(file .. ": failed to load image")
+   end
    local buff = fp:read("*a")
    local buff = fp:read("*a")
    fp:close()
    fp:close()
    return image_loader.decode_float(buff)
    return image_loader.decode_float(buff)
 end
 end
 function image_loader.load_byte(file)
 function image_loader.load_byte(file)
    local fp = io.open(file, "rb")
    local fp = io.open(file, "rb")
+   if not fp then
+      error(file .. ": failed to load image")
+   end
    local buff = fp:read("*a")
    local buff = fp:read("*a")
    fp:close()
    fp:close()
    return image_loader.decode_byte(buff)
    return image_loader.decode_byte(buff)