Awful File I/O Bug in my Penny Arcade Reader

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
AkumaATR
Posts: 11
Joined: Sun Oct 30, 2005 1:07 am

Awful File I/O Bug in my Penny Arcade Reader

Post by AkumaATR »

Program code here:
http://luaplayer.pastebin.com/493701

You have to create a /PSP/PHOTO/PENNY_ARCADE/CACHED_COMIC.JPG file
on your memory card in order to test this (i'm not sure how to make the file created if it doesn't already exist yet...) Even though you make this file it will download the right one over it.

Remember to hit L trigger to get past the "--> Closed!" debug message and then L trigger again to attempt to reload the comic after first load (it won't work because of said bug) if you are willing to test this for me...

I've been stuck on this bug for way to long. I am at a complete loss as to what's going on. Part of me wants to blame the LUA implementation (maybe it's a LUA bug!), but I know better, because I've written simple tests to show that what I'm trying to do should work.

I took a few days off from some GBA work I'm doing to create a Penny Arcade Reader (PSP Lua App.). It connects to the Penny Arcade site and downloads the latest comic (originally stored in memory). Then I write it to a jpg on the memory card. this is so that i can reload it using Image.load() so that I don't have to do the jpeg loading work. you can think of that image file as a cache file on the memory card.

the greater part of the program is in a loop, because when the user hits the trigger buttons, i want them to be able to scroll through other comics than the latest. for now though, it's set up to just keep reloading the latest comic (from the web again, same steps as before) when the user presses a trigger. this is where the strangeness happens. other than needing to add my scrolling code (for panning over the comic) and a slight modification to allow for browsing through the comics with the triggers, as well a second viewing mode, and a button to save file perm. to memstick, the project is done (minus the bug i'm about to describe).

If anyone can help me get over this bug I'd be very appreciative. Bug description is as follows. On first iteration everything works as it should... it downloads the latest comic and displays it. The flow is download jpg data, open cache file, write it to cache file, close cache file, load from cache file via Image.load() (for each iteration). I put a temporary debug message in the program at this point which states that the cache file was properly closed after the write (hit the L trigger to pass it up)... but i don't think it was. This is because when you hit a trigger again, which should load the same comic over, it claims it can't open the cache file. this output message is a result of io.open(cache_filepath) returning nil. I can't figure out for the life of me why this won't open (it's like the file descriptor wasn't properly closed or whatever). this is always how it works... i can go back to PSP firmware menu, back in lua, run again, and it always works first time (downloads first comic). but then it always says that cache file can't be opened on the second iteration of the loop.

a program was tested however that simply opened a file for writing as "w+b" then wrote some stuff to it, then closed it, in a loop, and it worked without the same issue, so I doubt it's Lua's fault?

i've tried a TON of stuff, nothing working. if anyone can help me get it to the point that it reloads the same comic via the trigger press, as opposed to not being able to reopen that cache file, a release will be shortcoming, and a lot of thanks will be in order =-)
AkumaATR
Posts: 11
Joined: Sun Oct 30, 2005 1:07 am

To Clarify...

Post by AkumaATR »

I also tried using:

cached_file_path = "ms0:/PSP/PHOTO/PENNY_ARCADE/CACHED_COMIC.JPG"

(I didn't have the ms0: before) -- still no love. :-/
Shine
Posts: 728
Joined: Fri Dec 03, 2004 12:10 pm
Location: Germany

Post by Shine »

This was a bug in the JPEG loading function, it doesn't close the file. I've fixed this. After updating the toolchain and cleaning up the socket interface a bit, I'll release a new version.
AkumaATR
Posts: 11
Joined: Sun Oct 30, 2005 1:07 am

Sweet

Post by AkumaATR »

Awesome. I actually just minutes ago decided to download the source and have a look, and I noticed that there were no fclose() calls in loadJpegImage() and came back here to ask if that was the problem.

Thanks a lot, I'll get back to work on finishing this Penny Arcade Reader as soon as that new version of the Lua Player is up.

This was my first Lua app., and I must say you guys have done a great job bringing this to the PSP. The Lua Player is capable of much more than I realized going in...
Post Reply