[fxruby-users] Segmentation Fault involving FXMessageBox and sockets

Melton, Ryan rmelton at ball.com
Wed Mar 25 15:12:25 EDT 2009


I've been experiencing a strange crash that involves using FXMessageBox, and having another thread that is interacting with a socket.  

Attached is the code that very quickly crashes for me after pressing the "Press Me" button.  Note that the program will run forever until the

MessageBox is shown.  (I believe the same issue also exists with the File choosers.)

 

My system specs:

Windows XP SP2

Ruby 1.8.6 p0

FXRuby 1.6.17

 

Can anyone else recreate this on your system?

Thanks,

Ryan

 

require 'rubygems'

require 'fox16'

include Fox

 

require 'socket'

require 'thread'

 

class CrashMe < FXMainWindow

  

  def initialize (app, title)

    # Call the base class initializer first

    super(app, title)

 

    # Create a Vertical Frame for the application's contents

    @frame = FXVerticalFrame.new(self, LAYOUT_FILL_X|LAYOUT_FILL_Y|FRAME_SUNKEN)

    

    button = FXButton.new(@frame, "Press Me").connect(SEL_COMMAND, method(:handle_button_1))

    

    # Create thread to accept connections

    Thread.new do

      sockets = []

      

      #Create a socket to accept connections from clients

      addr = Socket.pack_sockaddr_in(9999, Socket::INADDR_ANY)

      listen_socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)

      listen_socket.bind(addr)

      listen_socket.listen(5)

    

      loop do

        socket, address = listen_socket.accept()

        sockets << socket

      end

    end       

    

    # Create client

    Thread.new do 

      loop do

        socket = Socket.new(Socket::AF_INET, Socket::SOCK_STREAM, 0)

        addr = Socket.pack_sockaddr_in(9999, '127.0.0.1')

        socket.connect(addr)

        loop do

          begin

            socket.recvfrom_nonblock(65542)

          rescue => error

          end

          sleep(0.01)

        end

      end

    end

  end

 

  def handle_button_1 (sender, sel, data)

    FXMessageBox.warning(self, MBOX_OK, 'Warning!', 'Are you sure?')

  end

 

  def self.run

    # Make application

    application = FXApp.new("NA", "NA")

 

    # Make window

    window = self.new(application, "Title")

    window.show

    

    # Create the application windows

    application.create

    

    # Run the application

    application.run    

  end # def self.run

 

end # class CrashMe

 

CrashMe.run




This message and any enclosures are intended only for the addressee.  Please  
notify the sender by email if you are not the intended recipient.  If you are  
not the intended recipient, you may not use, copy, disclose, or distribute this  
message or its contents or enclosures to any other person and any such actions  
may be unlawful.  Ball reserves the right to monitor and review all messages  
and enclosures sent to or from this email address.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/fxruby-users/attachments/20090325/51372e06/attachment-0001.html>


More information about the fxruby-users mailing list