gtk--: segfault in destructor of spinbutton!

I've found out now why my app crashes on exit, when the windows are destroyed.
A stack strace with gdb show that the Gtk_Spinbutton wants to delete its
Gtk_Adjustment. Now I've declared both elements on the stack, so they get
deleted automatically when the MainWindow gets destroyed. So in effect
Gtk_Adjustment gets killed twice!

So this is an ownership problem. In my opinion gtk-- should only delete
a contained object if it was created on the heap, but not if it lives on the
stack, as in that case it will "die" by itself, when the object it
lives in gets out of scope. Only I have no idea how to find out if an object
was created by "new" or just on the stack.

Maybe someone else knows more, or should I better create everything with new
and delete it in the destructor. But then how do I know if a container will 
delete what it contains or if I should do it myself?

Anyway, I'd be happy about some more insight about the conventions
gtk-- is supposed to follow...

Bye bye,


Here's the stack trace:

#0  0x8123747 in __libc_free ()
#1  0x80ff550 in ___builtin_delete (ptr=0xbffff5b4)
#2  0x80503a6 in Gtk_Adjustment::~Gtk_Adjustment (this=0xbffff5b4, __in_chrg=3)
at ./../adjustment.gen_h:78
#3  0x80618ee in Gtk_SpinButton::~Gtk_SpinButton (this=0xbffff60c, __in_chrg=2)
at ./../spinbutton.gen_h:82
#4  0x8049066 in HelloWorld::~HelloWorld (this=0xbfffdad8, __in_chrg=2) at
#5  0x8048734 in main (argc=1, argv=0xbffff8d0) at
#6  0x80480eb in _start ()

And a piece of code:
class HelloWorld : public Gtk_Window { // (1) 
  Gtk_Button b1,b2,b3;
  Gtk_HBox hbox;
  Gtk_VBox vbox;

  Gtk_Table table;
  Gtk_HRuler hruler;
  Gtk_VRuler vruler;
  MyDraw drw_area;
  Gtk_Adjustment zoomscale_adj;
  Gtk_SpinButton zoomscale_b;
  void  click_cb(int num){printf("Button %d clicked \n",num);};  
  gint ruler_motion_notify(GdkEventMotion *event)
      typedef gint (*MotionEventFunc)  (GtkWidget *,GdkEventMotion *);  
    GtkWidget *widget = GTK_WIDGET(hruler.gtkobject);  
    MotionEventFunc func =( MotionEventFunc)   (GTK_WIDGET_CLASS(GTK_OBJECT

    func((GtkWidget *)widget,event);
    widget = GTK_WIDGET(vruler.gtkobject);
    func =( MotionEventFunc)   (GTK_WIDGET_CLASS(GTK_OBJECT
    func((GtkWidget *)widget,event);


  gint delete_event_impl(GdkEventAny *) {
    printf("Ouch...I'm shot....Aahh!\n");
    return 0;

    b1("Oh no!"),b2("hi!"),b3("Some text"),
 /*bla bla bla */ 

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]