New to ruby & tk -- seg fault with many buttons

I’m trying to teach myself ruby/tk, and am getting a seg fault with the
program below (part of a hangman game). Actually, it only seg faults
some of the time (if you hit Quit right away, or just one letter, then
Quit).

I’m seeing the seg fault on a Debian 3.1 machine:

$ ./bb
You just hit the i button.
/usr/lib/ruby/1.8/tk.rb:1194: [BUG] Segmentation fault
ruby 1.8.2 (2005-04-11) [i386-linux]

Aborted

I tried it on a Mac, and it did not seg fault (ruby 1.8.1 (2003-12-25)
[powerpc-darwin]).
Also, odd things seem to make it work ok (removing the -w, putting
everything in the top frame, removing a few letter buttons).

I’ve searched the list and FAQ and google a bit, but didn’t see
anything obvious. Let me know if I’m just doing something stupid.
And thanks for any help.

jeff

#! /usr/bin/ruby -w

require ‘tk’

def guess(ch)
print “You just hit the #{ch} button.\n”
end

root = TkRoot.new { title “buggy buttons” }
top = TkFrame.new(root)
bottom = TkFrame.new(root)

quit=TkButton.new(top) { text ’ Quit '; command {exit}; pack }

g=TkButton.new(top) {text ‘g’; command {guess(‘g’)}; pack }
h=TkButton.new(top) {text ‘h’; command {guess(‘h’)}; pack }
i=TkButton.new(top) {text ‘i’; command {guess(‘i’)}; pack }
j=TkButton.new(top) {text ‘j’; command {guess(‘j’)}; pack }
k=TkButton.new(top) {text ‘k’; command {guess(‘k’)}; pack }
l=TkButton.new(top) {text ‘l’; command {guess(‘l’)}; pack }
m=TkButton.new(top) {text ‘m’; command {guess(‘m’)}; pack }
n=TkButton.new(bottom) {text ‘n’; command {guess(‘n’)}; pack }
o=TkButton.new(bottom) {text ‘o’; command {guess(‘o’)}; pack }
p=TkButton.new(bottom) {text ‘p’; command {guess(‘p’)}; pack }
q=TkButton.new(bottom) {text ‘q’; command {guess(‘q’)}; pack }
r=TkButton.new(bottom) {text ‘r’; command {guess(‘r’)}; pack }
s=TkButton.new(bottom) {text ‘s’; command {guess(‘s’)}; pack }
t=TkButton.new(bottom) {text ‘t’; command {guess(‘t’)}; pack }
u=TkButton.new(bottom) {text ‘u’; command {guess(‘u’)}; pack }
v=TkButton.new(bottom) {text ‘v’; command {guess(‘v’)}; pack }
w=TkButton.new(bottom) {text ‘w’; command {guess(‘w’)}; pack }
x=TkButton.new(bottom) {text ‘x’; command {guess(‘x’)}; pack }
y=TkButton.new(bottom) {text ‘y’; command {guess(‘y’)}; pack }
z=TkButton.new(bottom) {text ‘z’; command {guess(‘z’)}; pack }

top.pack
bottom.pack
Tk.mainloop

From: [email protected] (Jeff Knerr)
Subject: new to ruby & tk – seg fault with many buttons
Date: Wed, 3 May 2006 06:01:43 +0900
Message-ID: [email protected]

I’m trying to teach myself ruby/tk, and am getting a seg fault with the
program below (part of a hangman game). Actually, it only seg faults
some of the time (if you hit Quit right away, or just one letter, then Quit).
(snip)
$ ./bb
You just hit the i button.
/usr/lib/ruby/1.8/tk.rb:1194: [BUG] Segmentation fault
ruby 1.8.2 (2005-04-11) [i386-linux]

Could you try the latest version ?
It may be the bug which was fixed at last month.

$ ./bb
You just hit the i button.
/usr/lib/ruby/1.8/tk.rb:1194: [BUG] Segmentation fault
ruby 1.8.2 (2005-04-11) [i386-linux]

Could you try the latest version ?
It may be the bug which was fixed at last month.

That did it. I get some warnings, but I found some previous posts
that said they were expected and not a problem.

$ ruby -v
ruby 1.8.4 (2005-12-24) [i686-linux]
$ ./bb
/usr/local/lib/ruby/1.8/tk.rb:2313: warning: redefine encoding=
/usr/local/lib/ruby/1.8/tk.rb:2316: warning: redefine encoding
You just hit the i button.
$

I should have tried that first…sorry. Thanks for the help!

jeff