Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Tutorial fails: can't load image
- - By Garant Date 2011-05-04 09:53
Hey, everyone. I'm having a bit of trouble with (I believe?) my Gosu install. I can get the very first part of the tutorial done fine: window spawned and caption set. However, trying to load images fails every time. "Cannot load image file xyz.png." I used the same code from the tutorial and used every type of path I could (relative, full, full escaped, full un-escaped). Even attempting to run the Tutorial.rb file that comes with the gem results in "Cannot load image file media/Space.png." This happens in both 1.8.7 (system default, never updated) and 1.9.2 (managed by RVM). I have a feeling this is going to end up being a stupid blunder on my part, but can someone point me in the right direction here?

OS 10.6.7
Ruby 1.8.7/1.9.2
gosu 0.7.31
RVM 1.6.5
Parent - By jlnr (dev) Date 2011-05-04 12:12
Huh... I have messed around with exactly that part of image loading in 0.7.30/31. It seems to work for me and some others though. Do you happen to use Xcode sometimes? If you do, you can just run *any* Cocoa application, pause and enter this into the debug/gdb console:

po [[NSImage class] imageFileTypes]

This will list all the formats that Gosu should load without a problem.

Also, are you on a 32-bit or 64-bit system?
Parent - - By jlnr (dev) Date 2011-05-04 12:18
Alternatively, you can list the file types supported by NSImage by installing MacRuby in rvm, then using irb:

irb(main):005:0> framework 'AppKit'
irb(main):006:0> NSImage.imageFileTypes
=> ["'PDF '", "PDF", "pdf", "'PICT'", "PIC", "pic", "PCT", "pct", "PICT", "pict", "'EPSF'", "PS", "ps", "EPSI", "epsi", "EPSF", "epsf", "EPI", "epi", "EPS", "eps", "'BMPf'", "'PNTG'", "'TPIC'", "'BMP '", "'8BPS'", "'icns'", "'TIFF'", "'jp2 '", "'GIFf'", "'JPEG'", "'PNGf'", "HDR", "hdr", "EXR", "exr", "MAC", "mac", "PNT", "pnt", "PNTG", "pntg", "TARGA", "targa", "TGA", "tga", "CUR", "cur", "XBM", "xbm", "BMP", "bmp", "ICO", "ico", "PSD", "psd", "ORF", "orf", "MRW", "mrw", "RWL", "rwl", "RAW", "raw", "RW2", "rw2", "RAF", "raf", "CRW", "crw", "ICNS", "icns", "EFX", "efx", "JFAX", "jfax", "JFX", "jfx", "G3", "g3", "FAX", "fax", "TIF", "tif", "TIFF", "tiff", "DCR", "dcr", "ERF", "erf", "ARW", "arw", "SR2", "sr2", "SRF", "srf", "SRW", "srw", "PEF", "pef", "NRW", "nrw", "NEF", "nef", "3FR", "3fr", "FFF", "fff", "MOS", "mos", "CR2", "cr2", "DNG", "dng", "JPF", "jpf", "JP2", "jp2", "GIF", "gif", "JPE", "jpe", "JPEG", "jpeg", "JPG", "jpg", "PNG", "png"]
irb(main):012:0> NSImage.alloc.initWithContentsOfFile("/Library/Ruby/Gems/1.8/gems/gosu-0.7.31-universal-darwin/examples/media/Space.png")
=> #<NSImage:0x2005a4b00>


That is replicating pretty much what Gosu does when loading an image file. The last line should consequently yield 'nil' for you.
Parent - - By Garant Date 2011-05-04 22:43
I have (as far as I can tell) all the same supported image types that you listed. However, attempting to allocate an image does indeed yield 'nil.' Could this maybe be a problem with OS X not being able to find the file? I had to muck about in /etc/bashrc (and I think ~/.profile) to get RVM working, and I'm not totally confident I did it correctly (especially since I've uninstalled RVM once before: I don't know how well it cleans up after itself). If this is a possibility, perhaps someone could paste the contents of their own bashrc and profile and I could try with those.

Oh, and I'm running the 32-bit kernel.
Parent - - By jlnr (dev) Date 2011-05-05 00:11
The only line I have added to my .profile (I don't have a .bashrc) is

if [[ -s "$HOME/.rvm/scripts/rvm" ]]  ; then source "$HOME/.rvm/scripts/rvm" ; fi

But if you get as far as playing around with MacRuby and NSImage, I doubt that this is the problem :S

Does file loading in general work? For example, if I use MacRuby's irb from my home folder:

irb(main):005:0> NSData.dataWithContentsOfFile('.profile')
=> #<NSConcreteData:0x2000f45a0>


Just to find out if NSImage or paths are the problem.
Parent - - By Garant Date 2011-05-05 02:09
Nope, returns 'nil.' Which means there's something terribly wrong with my computer. =/

I skipped Xcode 3 and installed v4 from the App Store, maybe I should try v3?

Sorry that this isn't actually gosu-related. I'll take my problems to Stack Overflow if your next post isn't "Oh yeah, I've seen that before: do this." =)
Parent - - By jlnr (dev) Date 2011-05-05 03:11
Hmm that is all very mysterious indeed, especially since the system uses NSData and NSImage left and right, so these can't be internally broken. It appears that you have a Ruby-only problem that affects Apple APIs, but in all three separate installations o_O

One last thing I'd try (and then maybe add to Stack Overflow) is the last example, but using only the Ruby API. So, again, in your home folder (fresh Terminal with system Ruby):

>> File.read('.profile')
=> "...file contents here..."


Maybe the problem isn't related to Apple APIs after all...maybe *all* your paths are off. I was only focussing on the Apple stuff first because I thought it'd be a format problem, not a file-not-found one.
Parent - - By Garant Date 2011-05-05 08:57
Also not found. And I can't find anyone with an even remotely similar problem on Stack Overflow or via Google. I'm thinking I'll just reinstall OS X; wouldn't hurt to clean this thing out anyway. Thanks so much for your help, though. I'm a fan of gosu already just for your selfless tech support. Hopefully I'll be back here with a project (or *actual* gosu problem) in the near future.
Parent - By jlnr (dev) Date 2011-05-05 10:08
No problem and good luck!
Up Topic Gosu / Gosu Exchange / Tutorial fails: can't load image

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill