Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

FXMessageBox class methods are not threadsafe

#29

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

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

State: new
Milestone: none
Assigned to: lyle (at lylejohnson) lyle (at lylejohnson)

Activity

  1. lyle (at lylejohnson)
    lyle (at lylejohnson)

    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.

    November 11th, 2009 @ 10:37 PM

  2. lyle (at lylejohnson)
    lyle (at lylejohnson)

    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.

    November 11th, 2009 @ 10:37 PM

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.