Page 1 of 1

Why can't I open an image?

Posted: Mon Feb 25, 2013 9:53 pm
by tatarjj
Hello.

Sorry if this question has been asked, but I've searched the forum and found nothing.

I just got started working in LOVE today. I am working on a testing application, and I needed a simple GUI interface. LOVE seemed to fit the bill. I would rather not share my .love file, as it has some confidential information already in it. However, I would be willing to make a "sanitized" version if whatever my problem is is not immediately apparent.

So anyway, I cannot open images. On my desktop, I have a folder for my program that contains the following files/folders:

autoTest.love

love.exe
DevIL.dll
OpenAL32.dll
SDL.dll

autoTest.bat (a batch file that contains this text: START love.exe autoTest.love)

AND the following folders:
Scripts
resources

Scripts contains various other Lua scripts I want to leave in Lua, not be zipped up.

The resources folder contains images for my GUI.

However, I cannot load any images at all. first, I tried using this script to load images:
scriptsInstalled = love.graphics.newImage('./resources/scripts_installed.jpg')

I get an error: "Could not open file ./resources/scripts_installed.jpg. Does not exist."

So I changed it to this:
scriptsInstalled = love.graphics.newImage(love.filesystem.getWorkingDirectory() .. '/resources/scripts_installed.jpg')

I get the same error, but now it gives me the full path on my C:\ drive.

So then I tried to just open the file

local f = love.filesystem.newFile(love.filesystem.getWorkingDirectory() .. '/resources/scripts_installed.jpg')

Same problem.

I even tried moving the image to the same directory as the .love file and love.exe. Same problem.

No matter what I do, I can't get it to open an image file. And yes, the file name is correct.

Can anyone help me with this limited description, or do I need to make a sanitized version of my LOVE application so that you guys can see the problem yourselves?

Re: Why can't I open an image?

Posted: Mon Feb 25, 2013 10:07 pm
by Boolsheet
The love.filesystem wiki page states that it only gives access to two places. The game directory (either the directory with the main.lua or the contents of the Zip archive) and the save directory. Other places will not be accessible with the love.filesystem module. You cannot pass absolute paths to its functions. If it works for some functions, it's most likely because the underlying library (PhysicsFS) happens to allow it, but that's not by design.

Re: Why can't I open an image?

Posted: Mon Feb 25, 2013 10:25 pm
by tatarjj
Thank you very much! I read the filesystem documentation, but I misinterpreted what it meant by the two directories. I got it working now, by using this structure:

Base directory:
love files
autoTest -- folder

In in the "autoTest" folder

main.lua
Scripts -- folder
resources -- folder of images

Now, I can access my images like this:

scriptsInstalled = love.graphics.newImage('resources/scripts_installed.jpg')

Thanks once again!

IMO, it would be helpful if the file system library worked more like other file system libraries I've used...

Re: Why can't I open an image?

Posted: Mon Feb 25, 2013 10:27 pm
by Boolsheet
The problem is portability and keeping it neat and clean over all (currently 3 supported) platforms. I'm sure the developers thought about it, but PhysicsFS is here for a bit longer for now. :)

Re: Why can't I open an image?

Posted: Mon Feb 25, 2013 10:35 pm
by tatarjj
Boolsheet wrote:The problem is portability and keeping it neat and clean over all (currently 3 supported) platforms. I'm sure the developers thought about it, but PhysicsFS is here for a bit longer for now. :)
Copy that, I figured they must have had a reason...

Re: Why can't I open an image?

Posted: Mon Feb 25, 2013 10:46 pm
by tatarjj
What happens if I try to include lfs?

http://keplerproject.github.com/luafilesystem/

Can I use it instead of the default file system? Or will there be issues?

Re: Why can't I open an image?

Posted: Tue Feb 26, 2013 9:30 am
by Robin
There will be issues with those who use SELÖVE, a sandboxed version of LÖVE. For security reasons, a few things are disallowed (like running commands, e.g. "format C:\" or accessing random files on your computer, or loading C extensions (because in those extensions, anything goes)), and luafilesystem probably doesn't work without those things.

Otherwise, it will probably work for you.