LunaLua Can't Handle Attempting to Load Invalid Images?

This is the place for discussion and support for LunaLua and related modifications and libraries.

Moderator: Userbase Moderators

Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
Sambo
Snifit
Snifit
Posts: 211
Joined: Fri Jan 24, 2014 6:43 pm

LunaLua Can't Handle Attempting to Load Invalid Images?

Postby Sambo » Fri Oct 28, 2016 8:36 pm

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.

Hoeloe
Phanto
Phanto
Posts: 1465
Joined: Sat Oct 03, 2015 6:18 pm
Flair: The Codehaus Girl
Pronouns: she/her

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

Postby Hoeloe » Sat Oct 29, 2016 12:08 pm

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.

MECHDRAGON777
Pink Yoshi Egg
Pink Yoshi Egg
Posts: 6422
Joined: Fri Dec 20, 2013 6:40 pm
Flair: Nuclear Queen of Reversion.
Contact:

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

Postby MECHDRAGON777 » Thu Nov 03, 2016 4:27 am

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)


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 1 guest

SMWCentralTalkhausMario Fan Games GalaxyKafukaMarioWikiSMBXEquipoEstelari