FXRuby Fox::FXText breaks on threaded append

86 views Asked by At

I am trying to make a socket application with FXRuby, and everything works fine until the scroll bar gets added, and then the application crashes.

doing research shows that the threading is the issue, but i dont know any work around. any ideas?

this is the thread that causes the issue

def listen()
    Thread.new() do
        begin
            loop{
                #gets the message from the socket
                [email protected]()
                arr=msg.split(' ')
                msg=''
                case arr[0]
                when '/say'
                    arr.delete_at(0)
                    arr.each do |word|
                        msg+=word + ' '
                    end
                    add(msg)
                when '/cls'
                    @textArea.removeText(0, @textArea.length)
                when '/stp'
                    abort
                when '/conn'
                    @socket=EzSSL::Client.new(@ip,arr[1].to_i)
                    @textArea.removeText(0, @textArea.length)
                    @textArea.appendText("Connected to port #{arr[1]}")
                end
            }
        rescue
            #closes the ruby app on exception
            abort
        end
    end
  end

the add method adds the line of text to the FXText object

the EzSSL module is a gem i created to make secure socket connections with openssl, and works like a normal socket connection

i am new to the Fox-Toolkit and FXRuby, so any help is appreciated

1

There are 1 answers

0
Daniel On

You should update interface elements from the UI thread, like so:

app.runOnUiThread do
  @textArea.removeText(0, @textArea.length)
  @textArea.appendText("Connected to port #{arr[1]}")
end