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,

      Oliver

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
colorbutton.cc:159
#5  0x8048734 in main (argc=1, argv=0xbffff8d0) at colorbutton.cc:146
#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);};  
public:
  HelloWorld();
  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
(widget)->klass)->motion_notify_event);
 

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

  }

  gint delete_event_impl(GdkEventAny *) {
    printf("Ouch...I'm shot....Aahh!\n");
    Gtk_Main::instance()->quit(); 
    return 0;
  }
  
};

HelloWorld::HelloWorld():
    b1("Oh no!"),b2("hi!"),b3("Some text"),
    hbox(false,0),vbox(true,0),table(2,2,false),
    zoomscale_adj(1.0,0.1,100.0,0.1,1.0,10.0),
    zoomscale_b(&zoomscale_adj,0.0,1)
 /*bla bla bla */ 



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