#3 [0.6.0] Crash on attempt to change font

closed-fixed
David Hart
None
5
2010-08-29
2009-06-18
Anonymous
No

I click on "Options" => "Configure 4Pane." In the resulting popup dialog I select the tab "Display." The font selection is in the middle of the tab, see the attached screenshot. The input lines do not accept any input. All I can do is to click on "Change." When I do so, 4Pane crashes. Starting 4Pane from a terminal window yields the following output, right at the moment of the crash:

(4Pane:3401): GLib-GObject-WARNING **: invalid cast from `GtkScrolledWindow' to `GtkWindow'
Segmentation fault

My environment: gtk+ 2.16.2, wxGTK 2.8.10.

Discussion

  •  
    Attachments
  • The "Terminals" tab of the configuration dialog has the same option to change fonts. Unsurprisingly, the crash happens there, too.

     
  • David Hart
    David Hart
    2009-06-22

    • assigned_to: nobody --> dghart
     
  • David Hart
    David Hart
    2009-06-22

    Hi,

    Thank you for your report.

    >The input lines do not accept any input. All I can do is to click on "Change."
    That's supposed to happen. Once you've managed to change the font, the 'Use Default' button will be activated, so that you can easily revert to the original.

    >When I do so, 4Pane crashes.
    That is *not* supposed to happen:(

    However it doesn't crash here, on e.g. ubuntu jaunty or fedora 11 (gtk 2.16.1), and debian lenny (2.12.11).

    I'd very much like to be able to replicate this. Would you mind giving more details about your setup: which distro and version, how did you install/build wxWidgets and 4Pane?

    Is this a debug build of wxWidgets (and therefore of 4Pane)? If not, would it be possible for you to make one, then run 4Pane inside gdb. Do you have the wxWidgets samples (from the tarball, perhaps in some packages)? If so, could you build and run the 'font' sample, then choose 'Select > select font'. Does this crash too?

    Many thanks.

     
  • Hi,

    it is a little late for doing debug builds today. Also, I have no experience with gdb. I hope the following helps nevertheless:

    First, my distribution is "Linux From Scratch" -- everything is self-compiled. Don't worry, "everything" ranges from glibc to OpenOffice, and the system is stable.

    To the problem at hand. We can rule out wxWidgets as the cause of the crash. I compiled the wxWidget font sample. It produced the font dialog (from the menu, just as you described). Then I remembered that I also have other software that uses wxWidgets, namely "poedit." Poedit also produces the font dialog as expected.

    Then I compared your program's font-dialog-producer ("void ConfigureDisplay::OnChangeFont()", Configure.cpp, lines 2024-2036) with the one from the wxWidget font sample ("void MyFrame::OnSelectFont()", samples/font/font.cpp, lines 666-681). They are functionally identical, except for one line that I had already identified as the source of the crash. Whereas your code uses

    wxFontDialog dialog(page,data);

    the font sample uses

    wxFontDialog dialog(this,data);

    => The difference between "page" and "this" is it. <=

    Copying your own code from a few lines above, I preceded the critical line with "if (page == 0) return;". The crash still occurred, so it is not due to "page" being a null pointer. Then I forced a null pointer, replacing your line with

    wxFontDialog dialog(NULL,data);

    and now the font dialog came up! It also worked flawlessly, except that the dialog was not modal now of course. But it did change 4Pane's font.

    Finally, on a hunch, I replaced "page" with "page->FindWindow(wxT("TreeDefaultFontBtn"))". The resulting console window error message differed in an interesting way from the one that I reported initially, it was now:

    (4Pane:331): GLib-GObject-WARNING **: invalid cast from `GtkButton' to `GtkWindow'
    Segmentation fault

    So the error message seems to reflect the object class of the first function parameter. Which is surprising to me because the first parameter is just the parent window, and should not need any active treatment inside the function call.I am not a C++ programmer; maybe you have an idea what all that means. One possibility is that the object hierarchy in that part of 4Pane's configuration is somehow wrong, and that "page" holds something unexpected at the moment of the call. That does however not explain why the error occurs only on my system, but not on yours (and dozens/hundreds of others). Another possibility is that my compiler is less forgiving, or is maybe flawed. My compiler is GCC 4.40. Note however that I compiled both poedit and the wxWidget font sample with it, where the font dialog successfully appeared. A third possibility is the (small) difference between your GTK (2.16.1) and mine (2.16.2) -- but again, I used the same GTK for compiling poedit and the font sample.

    So overall there is no clear explanation, but at least we know the critical line in the source code.

     
  • Before someone asks for a copy: the compiler is of course version 4.4.0, not 4.40 ...

     
  • David Hart
    David Hart
    2009-06-23

    >First, my distribution is "Linux From Scratch" -- everything is
    >self-compiled.
    Ah. Not the easiest setting for me to replicate, then :(

    >We can rule out wxWidgets as the cause of the
    >crash. I compiled the wxWidget font sample. It produced the font dialog
    >(from the menu, just as you described). Then I remembered that I also have
    >other software that uses wxWidgets, namely "poedit." Poedit also produces
    >the font dialog as expected.
    Agreed. It also can't be the particular gtk2 or gcc version, unless all these are interacting in some strange way only when the parent (or grandparent) widget is a wxNotebookPage.

    If so, other dialogs should also crash. What happens if you click the 'Configure small-toolbar Tools' or the 'Configure Tooltips' buttons? Do their dialogs crash too? If not, it suggests that the main fault lies within wxFontDialog.

    >wxFontDialog dialog(NULL,data);
    >and now the font dialog came up!
    This isn't as strange as it looks. wxDialogs are allowed to have a NULL parent.
    The reason I don't normally do so is that it sometimes messes up the z-order. This is mainly a problem when one dialog launches another: when the second dialog closes, you want to see the first one on top, not some other window.

    The other thing you could try, if you have time and inclination, is to replace 'page' with 'MyFrame::mainframe' which is a pointer to the main frame, rather than a notebookpage. It would be interesting to know if that crashes too, especially as the TreeDefaultFontBtn button did.

    >except that the dialog was not modal now of course.
    It _is_ still modal (here, at least): clicking elsewhere on the program doesn't do anything; however it doesn't stay-on-top. But it doesn't anyway, whatever the parent (I think that's a gtk2 thing).

    >Also, I have no experience with gdb.
    If you want to try, it's not difficult (at least, not for this). Start it with:
    gdb /path/to/4Pane
    Then run it with:
    r
    When the crash happens, get a backtrace with
    bt
    Quit with 'q'

    I'm most grateful to you for your efforts in solving this. Unless there are more developments, I'll replace 'page' with NULL for the font dialogs, as this causes no side-effects.

     
  • > What happens if you click the 'Configure small-toolbar Tools' or the 'Configure Tooltips' buttons?

    Both work as expected -- they bring up their respective dialogs.

    > replace 'page' with 'MyFrame::mainframe'

    Yes, that made the "Change" button work; the font dialog appeared.

    > gdb

    Here is the output from running 4Pane under gdb and triggering the crash. Not very useful, I guess. I'll compile unstripped debug versions of wxWidgets and 4Pane and try again with those.

    (no debugging symbols found)
    (no debugging symbols found)
    (no debugging symbols found)

    (4Pane:19384): GLib-GObject-WARNING **: invalid cast from `GtkScrolledWindow' to `GtkWindow'

    Program received signal SIGSEGV, Segmentation fault.
    0xb728f8e5 in g_datalist_id_get_data () from /usr/lib/libglib-2.0.so.0
    (gdb) bt
    #0 0xb728f8e5 in g_datalist_id_get_data () from /usr/lib/libglib-2.0.so.0
    #1 0x00000241 in ?? ()
    #2 0xb74e9352 in g_object_get_data () from /usr/lib/libgobject-2.0.so.0
    #3 0x00000198 in ?? ()
    #4 0x00000000 in ?? ()
    (gdb) q
    The program is running. Exit anyway? (y or n) y

     
  • Okay. I compiled debug versions of: glib, gtk, wxGTK, 4Pane. Now I get warnings (including "critical" ones), but no longer a crash. Here is the console window output; I describe the time course afterwards.

    [~] gdb 4pane
    GNU gdb 6.8
    Copyright (C) 2008 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law. Type "show copying"
    and "show warranty" for details.
    This GDB was configured as "i686-pc-linux-gnu"...
    (gdb) r
    Starting program: /usr/bin/4pane

    (4pane:19455): Gdk-CRITICAL **: gdk_x11_atom_to_xatom_for_display: assertion `atom != GDK_NONE' failed

    (4pane:19455): GLib-GObject-WARNING **: invalid cast from `GtkScrolledWindow' to `GtkWindow'

    (4pane:19455): Gtk-CRITICAL **: gtk_window_set_transient_for: assertion `parent == NULL || GTK_IS_WINDOW (parent)' failed

    (4pane:19455): Gdk-CRITICAL **: gdk_x11_atom_to_xatom_for_display: assertion `atom != GDK_NONE' failed

    Program exited normally.
    (gdb) q

    The first warning appears when I choose "Options" -> "Configure 4Pane" from the menu. It appears together with the configuration dialog showing up.

    The remaining three warnings appear when I click the "Change" button that previously had triggered a crash. All three appear together (there is no noticeable delay in between), and at the same time, the font dialog shows up.

    Gdb does not accept the "bt" command while 4Pane is running. After closing 4Pane, the "bt" command leads to the output "No stack." Needless to say, the warnings are exactly the same when I start 4Pane directly from the command line, not from gdb. Sorry, that's all I have.

     
  • David Hart
    David Hart
    2009-06-25

    • status: open --> closed-fixed
     
  • David Hart
    David Hart
    2009-06-25

    >Okay. I compiled debug versions of: glib, gtk, wxGTK, 4Pane. Now I get
    >warnings (including "critical" ones), but no longer a crash.
    It's difficult to know why a crash happens in release, not in debug. Sometimes a timing issue, sometimes some variable gets zeroed in debug...

    >Gdb does not accept the "bt" command while 4Pane is running.
    That's right. You can use Ctrl-C to pause the program, or use breakpoints to pause it at predefined places. No matter, though.

    >> What happens if you click the 'Configure small-toolbar Tools' or the
    >> 'Configure Tooltips' buttons?
    >Both work as expected -- they bring up their respective dialogs.
    >> replace 'page' with 'MyFrame::mainframe'
    >Yes, that made the "Change" button work; the font dialog appeared.

    That strongly suggested that the problem was within the wxFontDialog code, and that it was the type of parent that mattered.

    As it happened, all your effort in creating debug builds didn't add much information; sorry. However it did make me look harder at the gtk messages. (I get these too, but I've got used to ignoring them as they're very common, and seldom seem to matter.) Stepping though the wxWidgets fontdialog code, though, I could see what was going wrong to cause the messages (and your crash), and what the solution is. I've reported it as a wxWidgets bug (http://trac.wxwidgets.org/ticket/10929), so it's likely to be fixed in the next release.

    Meanwhile I've changed the parent to NULL for these dialogs, so the crash won't happen in future 4Pane releases.

    Again, I'm very grateful to you for your bug report, and your great help in correcting it.

     
    • status: closed-fixed --> open-fixed
     
  • Thank you for having investigated into this. I will use your upstream patch.

     
  • David Hart
    David Hart
    2010-08-29

    • status: open-fixed --> closed-fixed