Not logged inGosu Forums
Forum back to libgosu.org Help Search Register Login
Up Topic Gosu / Gosu Exchange / Image.new gives unknown error
- - By redcodefinal Date 2015-01-16 19:58 Edited 2015-01-16 20:09
When creating a new image with Gosu I get a very descriptive (sarcasm) "RuntimeError: Unknown Error"
gist

I'm new to Gosu so I apologise if this question is stupid but, I'm not sure what I'm doing wrong here.

Here's the repo of the code I'm working on, the issue happens in assets.rb @ line 19
github
Parent - - By RunnerPack Date 2015-01-16 23:06
Just a guess, but it's probably not finding the PNG file. You should generate an absolute filename based on the path of the script (e.g. using __FILE__).
Parent - - By redcodefinal Date 2015-01-16 23:42 Edited 2015-01-17 00:20
This seems a bit weird to me since in the Gosu examples (specifically CaptRuby) he uses relative pathing just fine. I'll give it a try and edit this post with results. I just wish the Error message was a little more descriptive because I have 0 clue what "Unknown Error" is supposed to convey.

EDIT: Didn't work :( I even have it puts the dir name and its super valid (RubyMine even links it for me so when I click the link I puts it correctly opens that file. What's weirder is that your method seems to work in IRB but not RubyMine or by running the script directly.
gist for error from rubymine
gist from irb
Specific code that is giving me trouble is now line 23
github
Parent - By RunnerPack Date 2015-01-17 00:52
Well, I did say it was a guess ;)
I think that error comes directly from the library (FreeImage?) used to load the image. If it's opening the right file, that error usually means it can't load the file, for some reason, e.g. unsupported (sub)format, damaged file, etc., but I've downloaded both block.png and tile.png, and a minimal program loads and displays either one perfectly fine (even from a relative path). I'm out of ideas :/

EDIT: jlnr beat me to it on FreeImage, and found the real problem :P
Parent - - By jlnr (dev) Date 2015-01-17 00:40
That's a libfreeimage error, the only one the library ever seems to return :)

As RunnerPack has pointed out, it's usually caused by the image file not being there. You are trying to load "block_shade,png" with a comma instead of a dot.

You can use relative filenames just fine, but you need to be sure to run the game from the right directory if you do. E.g. you cannot cd into content and then run ruby ../game.rb.
Using paths relative to __FILE__ can protect you against this. It all depends on how you distribute your game, I guess.
Parent - By redcodefinal Date 2015-01-17 02:59
You are totally right I'm a derp. I misread the error line and thought it was still happening on line 23. Thanks for the hand holding.
Up Topic Gosu / Gosu Exchange / Image.new gives unknown error

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill