record
block causes one of those new fangled dreaded segmentation faults the kids are always talking about. There's some weirdness with alpha transparency too, but the crashing bug is a bit more of a big deal.require 'gosu'
class Window < Gosu::Window
def initialize
super 480, 240, false
@draw_cache = { }
@image = Gosu::Image.new self, 'test.png', false
@font = Gosu::Font.new self, 'Helvetica', 16
end
def draw
draw_cache(:peachy_keen) do
# Appears to work without a hitch.
@font.draw "Hello, World!", 64, 0, 0
end
draw_cache(:reasonably_fine) do
# Transparency is rendered white even though it works as expected
# outside of a record
ed macro.
@image.draw 64, 16, 0
end
draw_cache(:this_causes_an_error) do
# OH NO SEGFAULT
draw_quad( 0, 0, Gosu::Color::WHITE,
0, 64, Gosu::Color::WHITE,
64, 64, Gosu::Color::WHITE,
64, 0, Gosu::Color::WHITE, 0)
end
end
def draw_cache id, z = 0, &block
unless @draw_cache.include? id
@draw_cache[id] = record(&block)
end
@draw_cache[id].draw 0, 0, z
end
end
Window.new.show
crash.rb:38: [BUG] Segmentation fault
ruby 1.9.2p136 (2010-12-25 revision 30365) [x86_64-darwin10.6.0]
-- control frame ----------
c:0008 p:---- s:0025 b:0025 l:000024 d:000024 CFUNC :record
c:0007 p:0037 s:0022 b:0020 l:000019 d:000019 METHOD crash.rb:38
c:0006 p:0037 s:0014 b:0014 l:000218 d:000218 METHOD crash.rb:26
c:0005 p:---- s:0011 b:0011 l:000010 d:000010 FINISH
c:0004 p:---- s:0009 b:0009 l:000008 d:000008 CFUNC :show
c:0003 p:0051 s:0006 b:0006 l:0018b8 d:0014a8 EVAL crash.rb:45
c:0002 p:---- s:0004 b:0004 l:000003 d:000003 FINISH
c:0001 p:0000 s:0002 b:0002 l:0018b8 d:0018b8 TOP
---------------------------
-- Ruby level backtrace information ----------------------------------------
crash.rb:45:in <main>'
crash.rb:45:in
show'
crash.rb:26:in draw'
crash.rb:38:in
draw_cache'
crash.rb:38:in `record'
-- C level backtrace information -------------------------------------------
record
from the documentation should have tipped me off. I've just noticed that the alpha for fonts is kind of messed up too, although it's not entirely missing like the image alpha.Image#from_text
.nil
s, attempting to dup
false and even invoking methods on garbage collected objects! ...none of which can I reproduce since they seem to have mysteriously stopped after I changed a couple of completely unrelated lines of code. Actually, most of those errors were found by changing seemingly unrelated code and I almost suspect that which one I got depended entirely on what memory addresses the objects were at or what kind of shoes the stack pointer was wearing. And I think that means I should have gone to bed a couple of hours ago.gen_eval
thing is a little too magical. I really like the library (banister's a clever fellow), but I'd rather have to write something like image.paint { |gfx| gfx.fill 0, 0, :color => :red }
if it meant I wouldn't have clever code creating hidden instance variables with illegal names and doing unspeakable things to my objects' implementation details. :D
paint
!!! :) im retiring it, yes it does some crazy shit, best to forget abou titimage.fill x, y, :color => blah
. Invoke all drawing actions directly on the image. paint
is dead to me now (i should probalby tell other people)gen_eval
(https://github.com/banister/gen_eval) used in texplay is an old one, i have subsequently fixed many of the bugs and brought in 1.9 compatibility (which the version in texplay doesn't properly hvae) however there is still a ridiculous edge case in 1.9 due to the annoying way ivars for objects are implemented, that i cannot get around (it doesn't result in segfaults it just results in weird behaviour). This is really sad as gen_eval
was so close to being brilliant, and it can work perfectly in ruby 1.8. local_eval
instead - the only difference between gen_eval and local_eval is that local_eval is not threadsafe (https://githubcom/banister/local_eval), oh and local_eval doesn't cause crashes (or at least it shouldn't as it's a much simpler concept)paint { ... }
for multiple operations is faster, but I assume that's out of date now. Great library, by the way, other than that gen_eval
weirdness. :)> Yeah, I suppose the absence of record from the documentation should have tipped me off. I've just noticed that the alpha for fonts is kind of messed up too, although it's not entirely missing like the image alpha.
> are there any plans for macros to be saveable in the future like images are?
> an example screenshot
render { @macro.draw x, y, z }
will work just as well as render { @image.draw x, y, z }
once you have implemented it. :)Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill