After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 512441 - Gdk::GC::create() - segmentation fault
Gdk::GC::create() - segmentation fault
Status: RESOLVED NOTABUG
Product: gtkmm
Classification: Bindings
Component: general
2.12.x
Other All
: Normal major
: ---
Assigned To: gtkmm-forge
gtkmm-forge
Depends on:
Blocks:
 
 
Reported: 2008-01-27 20:21 UTC by ghost99
Modified: 2008-01-27 22:15 UTC
See Also:
GNOME target: ---
GNOME version: 2.19/2.20



Description ghost99 2008-01-27 20:21:34 UTC
Please describe the problem:
Programs, that use Gdk::GC, are compiling well, but they are not work.

Steps to reproduce:
1. Copy code from below
2. g++ code.cc -o test `pkg-config gtkmm-2.4 --libs --cflags`
3. ./test
4. segmentation fault


Actual results:
gdb> r

Program received signal SIGSEGV, Segmentation fault.
_______________________________________________________________________________
     eax:BFAFF884 ebx:B7C67FF4  ecx:B7894FF4  edx:00000000     eflags:00210282
     esi:080A2698 edi:B7C66FB0  esp:BFAFF810  ebp:080A269C     eip:B7C4D7C9
     cs:0073  ds:007B  es:007B  fs:0000  gs:0033  ss:007B    o d I t S z a p c 
[007B:BFAFF810]---------------------------------------------------------[stack]
BFAFF840 : 98 26 0A 08  84 F8 AF BF - 80 F8 AF BF  5C BC 06 08 .&..........\...
BFAFF830 : 80 F8 AF BF  98 26 0A 08 - B8 F8 AF BF  73 D8 C4 B7 .....&......s...
BFAFF820 : B8 F8 AF BF  00 B0 F8 B7 - AC 26 0A 08  F4 7F C6 B7 .........&......
BFAFF810 : 9C 26 0A 08  C0 6F C6 B7 - 80 F8 AF BF  98 26 0A 08 .&...o.......&..
[007B:080A2698]---------------------------------------------------------[ data]
080A2698 : 50 91 4C B7  60 70 C6 B7 - 00 00 00 00  80 46 88 B7 P.L.`p.......F..
080A26A8 : 00 00 00 00  00 00 00 00 - 00 00 00 00  51 1F 00 00 ............Q...
[0073:B7C4D7C9]---------------------------------------------------------[ code]
0xb7c4d7c9 <_ZN3Gdk2GCC1ERKN4Glib6RefPtrINS_8DrawableEEE+67>:   mov    (%edx),%eax
0xb7c4d7cb <_ZN3Gdk2GCC1ERKN4Glib6RefPtrINS_8DrawableEEE+69>:   mov    -0xc(%eax),%eax
0xb7c4d7ce <_ZN3Gdk2GCC1ERKN4Glib6RefPtrINS_8DrawableEEE+72>:   mov    0x4(%edx,%eax,1),%eax
0xb7c4d7d2 <_ZN3Gdk2GCC1ERKN4Glib6RefPtrINS_8DrawableEEE+76>:   mov    %eax,(%esp)
0xb7c4d7d5 <_ZN3Gdk2GCC1ERKN4Glib6RefPtrINS_8DrawableEEE+79>:   call   0xb7c42c30 <gdk_gc_new@plt>
0xb7c4d7da <_ZN3Gdk2GCC1ERKN4Glib6RefPtrINS_8DrawableEEE+84>:   movl   $0x50,0x4(%esp)
------------------------------------------------------------------------------
0xb7c4d7c9 in Gdk::GC::GC () from /usr/lib/libgdkmm-2.4.so.1
gdb> backtrace 
  • #0 Gdk::GC::GC
    from /usr/lib/libgdkmm-2.4.so.1
  • #1 Gdk::GC::create
    from /usr/lib/libgdkmm-2.4.so.1
  • #2 main
    at test.cc line 10


Expected results:
Must return EXIT_SUCCESS;

Does this happen every time?
Happens every time

Other information:
#include <gtkmm.h>

int main(int argc, char *argv[])
{
  Gtk::Main kit(argc, argv);

  Gtk::DrawingArea drar;
  Glib::RefPtr<Gdk::Drawable> dr = drar.get_window();

  Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(dr); // segfaulting here

  return EXIT_SUCCESS;
}
Comment 1 Jonathon Jongsma 2008-01-27 22:15:43 UTC
Believe it or not, this is expected behavior.  Before a widget is 'realized', the drawable that you get back from get_window() is always NULL.  In your example code, the drawing area is not realized yet, so dr is NULL, so it segfaults when you pass it to GC::create().  The following example code should not crash:

#include <iostream>
#include <gtkmm.h>

void on_drawing_area_realize(Gtk::DrawingArea* drar)
{
    std::cout << "drawing area realized" << std::endl;
    Glib::RefPtr<Gdk::Drawable> dr = drar->get_window();
    if (dr) {
        std::cout << "drawable not null" << std::endl;
        Glib::RefPtr<Gdk::GC> gc = Gdk::GC::create(dr);
    }
}

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv);

    Gtk::DrawingArea drar;
    drar.signal_realize ().connect (sigc::bind
            (sigc::ptr_fun(on_drawing_area_realize), &drar));
    Gtk::Window win;
    win.add (drar);
    drar.show ();
    win.show ();

    Gtk::Main::run (win);
    return EXIT_SUCCESS;
}