#29 new
lyle (at lylejohnson)

FXMessageBox class methods are not threadsafe

Reported by lyle (at lylejohnson) | November 11th, 2009 @ 10:36 PM

In the following code, any of FXMessageBox.error, FXMessageBox.information, FXMessageBox.question, and FXMessageBox.warning will cause a seg-fault (WinXP, Ruby 1.8.6, FXRuby 1.6.13). But FXMessageBox.new followed by a call to execute seems OK. When the Thread.new line is removed, both cases work.

require 'fox16'; include Fox

app = FXApp.new
main = FXMainWindow.new app, 'Test'
button = FXButton.new main, 'button'
button.connect(SEL_COMMAND) {
  # this works
  # dialog = FXMessageBox.new(
  #   main, 'Test', 'test', nil, MBOX_OK|DECOR_TITLE|DECOR_BORDER
  # )
  # dialog.execute PLACEMENT_OWNER

  # this causes a seg-fault
  FXMessageBox.information main, MBOX_OK, 'Test', 'test'
}
Thread.new {button.text while true}
app.create
main.show PLACEMENT_SCREEN
app.run

Comments and changes to this ticket

  • lyle (at lylejohnson)

    lyle (at lylejohnson) November 11th, 2009 @ 10:37 PM

    Lyle asked the OP:

    Tim, what is it that you're trying to accomplish in this code (or in the actual code, if this is just an example)? Since all of the GUI stuff needs to take place in the main thread, we usually just reserve threads for long-running (or potentially long-running) activities, e.g. processing data in the background.

  • lyle (at lylejohnson)

    lyle (at lylejohnson) November 11th, 2009 @ 10:37 PM

    OP replied:

    This is just an example. The actual code has since been rewritten to use app.addTimeout with :repeat = true in place of the thread, and in fact I'm now calling app.disableThreads for faster GUI updates.

    Nonetheless, the segfault is real. You say that "all of the GUI stuff needs to take place in the main thread". But in the FXRuby examples folder, groupbox.rb uses a thread to update a clock. And if you remove the sleep call on line 373, then run the program, click "First", and choose an option from the dropdown, it segfaults after a call to FXMessageBox.information, just like this example.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

FXRuby is a library for developing powerful and sophisticated cross-platform graphical user interfaces (GUIs) for your Ruby applications. It’s based on the FOX Toolkit, a popular open source C++ library developed by Jeroen van der Zijp. What that means for you as an application developer is that you’re able to write code in the Ruby programming language that you already know and love, while at the same time taking advantage of the performance and functionality of a featureful, highly optimized C++ toolkit.

Shared Ticket Bins

People watching this ticket

Tags

Pages