Hello everyone. First time here.
I’m posting a debug question because I’ve searched google all over and I
can’t find any other instances of this occurring. And even though it may
be a common error due to a stupid mistake by me, who is just learning
ruby and wx, for some odd reason the internet seems devoid of a
solution. I’ve even searched this forum and the error message is not
here either.
What happens is, the script brings up the login/create window just fine
the first time, but if the user enters too short a password and the
script tries to bring the same window up a second time for another
chance at input, the program crashes with exception “Already Initialized
Constant THE_APP”. I’ve tried rewriting it multiple ways, even the basic
App.run do method. Still no luck.
It seems like I’m not doing something that is needed to completely
destroy the instance of App, as the second time I call it no matter what
it always crashes with the exception.
What’s funny is, I had this login/create window already done using the
TK library and since I had an old version of the library, it had a bug
in PMW which basically caused the same kind of behavior as this bug is
causing. I could only bring up one instance of anything, if another was
ever created, even after all other instances had been destroyed, the
program would crash and tell me that a constant was already initialized.
Without a way to fix it, I moved on to shoes, which I quickly dismissed
because it was WAY too hard to try and get shoes to work from within my
ruby script instead of as a script-launcher. Then I spent a good 5 hours
researching a way to make “require ‘wx’” work, turns out ubuntu 10.04
needs some special installation procedures. Finally got that working,
only to find out that, yep, I can only create one instance of a window
per program run… again… XD
I realize that I can just handle the string check in the button code to
avoid this one occurrence. However, that won’t fix the problem if I need
to be able to reopen a window later in the program. The real problem is
that later on I will be developing a lot of GUI windows for this client
that will need to be opened, then closed, then reopened, then closed,
then reopened, over and over and over again, in order for players to
build. If I can’t do it with the first window, it’s not worth building
all the subsequent windows or even continuing on the project until I can
find a GUI that allows me to create a second instance of a particular
window sometime after the first instance had been destroyed.
Here’s the contents of obtainlogin.rb. This file is required in the main
ruby script.
I’m using Ubuntu 10.04 Lucid and Ruby 1.8
Error: “Already Initialized Constant THE_APP” upon second run of App.
class LoginFrame < Frame
def initialize()
super(nil, -1, ‘Login Or Create’)
# First create the controls
@my_panel = Panel.new(self)
@userid_label = StaticText.new(@my_panel, -1, ‘User ID:’,
DEFAULT_POSITION, DEFAULT_SIZE, ALIGN_CENTER)
@userid_textbox = TextCtrl.new(@my_panel, -1, ‘’)
@password_label = StaticText.new(@my_panel, -1, ‘Password:’,
DEFAULT_POSITION, DEFAULT_SIZE, ALIGN_CENTER)
@password_textbox = TextCtrl.new(@my_panel, -1, ‘’, :style =>
TE_PASSWORD)
@connect_but = Button.new(@my_panel, -1, ‘Connect’)
# Bind controls to functions
evt_button(@connect_but.get_id()) { |event|
connect_but_click(event)}
# Now do the layout
@my_panel_sizer = BoxSizer.new(VERTICAL)
@my_panel.set_sizer(@my_panel_sizer)
@my_panel_sizer.add(@userid_label, 0, GROW|ALL, 2)
@my_panel_sizer.add(@userid_textbox, 0, GROW|ALL, 2)
@my_panel_sizer.add(@password_label, 0, GROW|ALL, 2)
@my_panel_sizer.add(@password_textbox, 0, GROW|ALL, 2)
@my_panel_sizer.add(@connect_but, 0, GROW|ALL, 2)
show()
end
def connect_but_click(event)
$userid = @userid_textbox.get_value
$password = @password_textbox.get_value
close
end
end
class LoginApp < App
def on_init
LoginFrame.new
end
end
def areThereIllegalCharactersInLoginInfo
tBool = false
for i in (0…$userid.length)
if $userid[i] < 32 or $userid[i] > 126
tBool = true
end
end
for i in (0…$password.length)
if $password[i] < 32 or $password[i] > 126
tBool = true
end
end
return tBool
end
def obtainLoginInfo
passBool = false
while passBool == false
#LoginApp.new.main_loop() # This was the original line, I changed it
to try and fix the problem.
tApp = LoginApp.new
tApp.main_loop()
tApp = nil # I added this line to try and fix the problem, it does
not help at all.
passBool = true
if $userid.length < 4 or $userid.length > 20 or $password.length < 4
or $password.length > 20
passBool = false
puts “Please provide a User ID and Password which are at least 4
characters long and at most 20 characters long.”
end
if areThereIllegalCharactersInLoginInfo == true
passBool = false
puts “Please provide a User ID and Password which contain only
standard characters. Special characters are not permitted.”
end
end
end