-
-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SF::View#dup broken #34
Comments
I stumbled upon this while trying to replace views. I tried to temporarily save |
Hmm? Seems to work require "crsfml"
a = SF::View.new
a.reset(SF.float_rect(100, 100, 400, 200))
b = a.dup
p! b.size # => SF::Vector2(Float32)(@x=400.0, @y=200.0) |
I think it's require "crsfml"
w = SF::RenderWindow.new
a = w.view
p! a.size # => SF::Vector2(Float32)(@x=1000.0, @y=1000.0)
b = a.dup
p! b.size # Error: wrong number of arguments for 'SF::View::Reference.new' (given 1, expected 2)
|
Somehow, require "crsfml"
class Test
@view : SF::View
def initialize
@view = SF::View.new
end
def try_dup
@view.dup
end
end
t = Test.new
p! t.try_dup # Error: wrong number of arguments for 'SF::View#initialize' (given 1, expected 2, 0) / In lib/crsfml/src/graphics/obj.cr:4463:27 |
Wow, now that could very well be a Crystal bug. Thanks, I'll check that separately, even though my fix would've gotten both. |
So I reduced the sub-issue to this: class Foo
def initialize()
end
def initialize(copy : Foo)
end
def dup() : self
return typeof(self).new(self)
end
end
class Bar < Foo
def initialize(x : Int32)
end
end
class Test
@foo : Foo = Foo.new
def foo_dup
@foo.dup
end
end
Test.new.foo_dup
And I concluded that this is not a bug. It happens due to Crystal's reduction of a type to the whole class hierarchy. I suppose these conditions cause |
Certainly interesting |
I think the fix actually introduced a new bug related to duplicating certain objects derived from abstract structs. The following code leads to an error: a = SF::Event::Resized.new
b = a.dup
Admittedly, there are few scenarios in which you'd want to copy an event, but I stumbled upon this while trying to bind crSFML to Ruby using Anyolite. I can construct a workaround, but it still might be an issue unless this is intended in some way. |
Hi, it seems like
SF::View#dup
is broken, because it tries to call initialize of eitherSF::View
orSF::View::Reference
(which appears twice insrc/graphics/obj.cr
btw), both of which do not accept aSF::View
instance as a single parameter.The text was updated successfully, but these errors were encountered: