Page 1 of 1

LunaLua Can't Handle Attempting to Load Invalid Images?

Posted: Fri Oct 28, 2016 8:36 pm
by Sambo
if I call loadImage and don't give it a valid file name, it throws an error. I can fix it with a wrapper, but why doesn't it have one built in?

And no, I'm not intentionally giving it an invalid file name to see if I can break it. It's supposed to try to load an image as part of a loop. The images it can load depend on the images the user places in the folder.

Re: LunaLua Can't Handle Attempting to Load Invalid Images?

Posted: Sat Oct 29, 2016 12:08 pm
by Hoeloe
Sambo wrote:if I call loadImage and don't give it a valid file name, it throws an error. I can fix it with a wrapper, but why doesn't it have one built in?

And no, I'm not intentionally giving it an invalid file name to see if I can break it. It's supposed to try to load an image as part of a loop. The images it can load depend on the images the user places in the folder.
Uhhh, that's not correct. Graphics.loadImage returns nil if you provide an invalid path.

However, Misc.resolveFile also returns nil if no relevant image could be found, and Graphics.loadImage WILL error if you try to load nil instead of an actual path. Which is sensible, because nil just means "non-existent data", of COURSE you'll get an error for trying to load with a path that doesn't exist (note that's distinct from "the file doesn't exist", in this case, the path itself doesn't exist). This is intended and sensible system design - passing "nil" to this is ALWAYS an error case, so it's valid for it to error when this happens. It makes diagnosing problems a lot easier.

Just do a nil check on the result of Misc.resolveFile.

Re: LunaLua Can't Handle Attempting to Load Invalid Images?

Posted: Thu Nov 03, 2016 4:27 am
by MECHDRAGON777
This is what caused one of my codes to error becuase I could never find the error until I looked in the HUD folder a few months latter to find I misspelled the image name. (Spelled right in the .lua, wrong on the physical image name)