This code is causing a very strange exception in Chingu, a game library for ruby that depends upon the Gosu 2D game framework:
class StopSignAttack < Chingu::Window
def initialize
super(1000, 1000, false)
self.input = { :escape => :close }
self.caption = "Stop Sign ATTACK!!!"
push_game_state(Start.new)
end
end
The value of the input property for the Chingu::Window should simply cause the game window to close when pressing the escape key. The window closes when pressing the escape key, but bombs badly with this exception:
/Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/chingu-0.8.1/lib/chingu/helpers/input_dispatcher.rb:63:in `block in dispatch_input_for': undefined method `button_down?' for nil:NilClass (NoMethodError)
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/chingu-0.8.1/lib/chingu/helpers/input_dispatcher.rb:62:in `each'
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/chingu-0.8.1/lib/chingu/helpers/input_dispatcher.rb:62:in `dispatch_input_for'
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/chingu-0.8.1/lib/chingu/window.rb:148:in `block in intermediate_update'
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/chingu-0.8.1/lib/chingu/window.rb:148:in `each'
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/chingu-0.8.1/lib/chingu/window.rb:148:in `intermediate_update'
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/chingu-0.8.1/lib/chingu/window.rb:133:in `update'
from stop_sign_attack.rb:24:in `<main>'
I’ve tried implementing the close method in the Chingu::Window, calling the super class close method:
def close
super.close
end
And I get this exception when pressing the ESC key:
stop_sign_attack.rb:23:in `close': undefined method `close' for nil:NilClass (NoMethodError)
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:19:in `rescue in block (2 levels) in <class:Window>'
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:12:in `block (2 levels) in <class:Window>'
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:26:in `show'
from /Users/sams/.rvm/gems/ruby-1.9.3-p0/gems/gosu-0.7.41-universal-darwin/lib/gosu/swig_patches.rb:26:in `show'
from stop_sign_attack.rb:28:in `<main>'
Any ideas are appreciated.
You left off some information that would allow someone to debug this. For example, you’re pushing a game state called Start, but the Start class is not declared in your example. but you haven’t shared that portion of the code. I created the following sample project to test out what you’ve got there:
This works just fine, exiting without any exception when I press escape.