Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Gosu::Image equivalance
- - By RavensKrag Date 2011-01-15 19:46
I'm getting a very odd bug here. 

img =$window, "./Sprites/Effects/Aero.png",false)
img2 = img.clone
assert_equal img.to_blob, img2.to_blob #This works fine
assert_equal img, img2 #This does not

I have defined Gosu::Image#== as follows

def ==(arg)
  if arg.class == Gosu::Image
    return self.to_blob == arg.to_blob
    return self.== arg

Can anyone tell me why this does not work?
Parent - - By banister Date 2011-01-15 23:12
is this with texplay required? im still not sure of the issue, but texplay does redefine the #clone method for Gosu::Image
Parent - - By RavensKrag Date 2011-01-15 23:27
Yes, I do have texplay required.

On the topic of texplay, I noticed that texplay defines Gosu::Image#new instead of Gosu::Image#initialize, which I thought was weird, but I suppose that's a bit off topic... I just remembered I took a brief look at that part of the code, and thought it could be possibly related.
Parent - - By banister Date 2011-01-15 23:58 Edited 2011-01-16 00:10
hehe, I wrote that part of the code 2 years ago (it needs a major refactor along with that whole file). I'm not sure why i do that, im sure i had good reason for it at the time, but that reason then may no longer be relevant now. I don't think it's related to yoru issue though
Parent - By RavensKrag Date 2011-01-19 09:26
It caused some other issue before though.  Unfortunately, the code that triggered that error was so horrendous I simply trashed it, so I couldn't tell you exactly what that problem was... The traceback put the blame somewhere in Gosu::Image#clone or #new, so it could be related to this. 

I'm really just taking vaguely-educated stabs in the dark though.
Parent - - By jlnr (dev) Date 2011-01-16 02:56
No idea, but a nit-pick: you need to compare either width or height too. Otherwise, it can theoretically happen that two images of the same area but different dimensions contain the same color values :)
Parent - By RavensKrag Date 2011-01-19 09:24
Took me a while to understand how that would happen, but I get it now.  Made sure to add that to the code.  This has the added benefit of short-circuiting the check if the dimensions of the images are not the same.
Parent - - By meustrus Date 2011-01-18 22:21
First thing, don't use "arg.class == Gosu::Image", use "arg.is_a?(Gosu::Image)" because that also checks inheritance (although if you don't want to check inheritance, you don't have to, but that might be your problem caused by Texplay; perhaps you can debug this with "puts arg.class, arg.ancestors")

Second, I suspect that if you ever have an argument that wasn't a Gosu::Image it could get stuck in an infinite loop; use "return false" instead of "self.==arg".

Try adding an "assert_equal img.class, img2.class" for debugging.
Parent - By RavensKrag Date 2011-01-19 09:23
Good point about using #is_a?, I'll change that right away.  However, correct me if I'm wrong, but I believe as Texplay edits the Gosu::Image class itself, rather than creating a descendant class, this should not be a problem in this instance.

Ah, I had meant to do arg.==self, but I suppose it's really just better to return false.  Will do.

I already checked to make sure both variables were instances of Gosu::Image.   I simply did not include that in this snippet.

Thanks for the help, although these changes still do not fix the problem.
Up Topic Gosu / Gosu Exchange / Gosu::Image equivalance

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill