RE: [gtk-list] Re: gtk--: Really weird thing!!



Now as I've upgraded to gtk+-0.99.4 and gtk--0.7.12 I've found a real strange
bug. I attach a little test program that makes a window with a drawing area and
3 buttons. The third one calls a callback that should open a
ColorselectionDialog. This callsback is in its own class, because it is 
part of a color displaying button, but this is unimportant here.

The  strange thing is that the program works if you construct the main window 
in its own class, but not if you do it from main(). Also the crash does not
depend on what you do exactly  in the callback, I also had it crash when I just
 tried to change a GC. It seems it is somewhere in the signal handlers.

This is what gdb says:

Signal_proxy0<void, Gtk_Widget>::operator() (this=0x2de) at
/usr/local/include/gtk--sig.h:1191
(xxgdb) print sender->gtkobject
Cannot access memory at address 0x2e2.
(xxgdb) print signal_name
Cannot access memory at address 0x2de.
(xxgdb) step

Program received signal SIGSEGV, Segmentation fault.
0x8049f5a in Signal_proxy0<void, Gtk_Widget>::operator() (this=0x2de) at
/usr/local/include/gtk--
sig.h:1191 

Now the two programs, have fun with them!
( I compiled them with gcc 2.7.2, and I think it didn't happen with gtk0.99.3
and gtk--0.7.9)

bye bye, Oliver 
-------------------------------------------------------------------------------
 
/* This is -*- C++ -*-  */
#include <gtk--.h>

//
// hello.cc
// This program crashes with a segfault when ColorButton::test_cb is 
// called and gtk 
// should open a color selector. The Main window is constructed directly
// from main().
// Just press the  lower button!

GdkWindow * gdkmainwindow; // Awful global that I need for creating a pixmap
// when it's object still doesn't have a window

// Pixmap stuff is commented out ...
class ColorButton : public Gtk_Button {
public:
  ColorButton(gchar * label):Gtk_Button(){
    GdkWindow * win = GTK_WIDGET(gtkobject)->window;
    GtkStyle * style= GTK_WIDGET(gtkobject)->style;
    GtkWidget * widget =GTK_WIDGET(gtkobject);
  
    /*   pixmap = gdk_pixmap_create_from_xpm (gdkmainwindow, &mask,
      		                         &style->bg[GTK_STATE_NORMAL],
					 "3DRings.xpm");
      
    pix = new Gtk_Pixmap(pixmap,mask);
    pix->show();
    add(pix);
    pix->show();*/
  }
  ~ColorButton()
  {/* if (pix) delete pix;
    if (col_gc) gdk_gc_destroy(col_gc);
    gdk_pixmap_unref(pixmap);
    gdk_bitmap_unref(mask);*/

  }

void  test_cb()
  {
  
    if (!colorsel) colorsel = new Gtk_ColorSelectionDialog("Select color!");
    colorsel->show();
    }
    

private:
  //  GdkPixmap *pixmap;
  //  GdkBitmap *mask;
  //  GdkGC *col_gc=NULL;
  // Gtk_Pixmap *pix;
  Gtk_ColorSelectionDialog *colorsel;
};

//Unimportant class for the buggy behavior... 
class MyDraw : public Gtk_DrawingArea {

public: 
MyDraw();
gint expose_cb(GdkEventExpose *) { // (5)
	GtkWidget *widget;    
	printf("Ouch...I'm exposed!\n"); 
    	widget = GTK_WIDGET(gtkobject);
	gdk_draw_rectangle(widget->window,
                            widget->style->white_gc,
                            TRUE,
                            0, 0,
                            widget->allocation.width,
                            widget->allocation.height);
	return 0;
  }
gint button_press_cb(GdkEventButton *) { // (5)
    printf("Ouch...pressed!\n"); 
    return 0;
  }
gint motion_notify_cb(GdkEventMotion *) { // (5)
    printf("Ouch...moved!\n");
    return 0; 
  }
/*gint button_press_cb2(GdkEventButton *) { // (5)
    printf("Ouch...callback 2!\n"); 
    return 0;
  }*/  

};
MyDraw::MyDraw(){
  printf("set_events\n");
  set_events(GDK_EXPOSURE_MASK         
           | GDK_BUTTON_PRESS_MASK
           | GDK_POINTER_MOTION_MASK
           | GDK_POINTER_MOTION_HINT_MASK);
	connect(expose_event,this,&expose_cb);
	connect(button_press_event,this,&button_press_cb);
        connect(motion_notify_event,this,&motion_notify_cb);
     //   connect(button_press_event,this,&button_press_cb2);
}


int main( int argc, char **argv )
{
  Gtk_Main m( &argc, &argv ); 
  Gtk_Window w;
  Gtk_Button b1("button 1"),b2("button 2");
  ColorButton cbutton("test");
  Gtk_HBox hbox(true,0);
  Gtk_VBox vbox(true,0);
  MyDraw drw_area;
  w.border_width(10);
  drw_area.set_usize(100,100);
  hbox.pack_start(&drw_area);
  vbox.pack_start(&b1);
  vbox.pack_start(&b2);
  vbox.pack_start( &cbutton);  
  hbox.pack_start(&vbox);

  //connect( b.clicked, Gtk_Main::instance(), &Gtk_Main::quit );
  //connect( b1.clicked,this , &click_cb,1);
  //connect( b2.clicked,this , &click_cb,2);
  connect(cbutton.clicked,&cbutton, &ColorButton::test_cb);
  cbutton.show();
  b1.show();
  b2.show();
  drw_area.show();
  vbox.show(); 
  hbox.show();
  w.add(&hbox); 
  //w.set_usize( 100,20 ); 
  w.show(); 
  
  m.run();
  return 0;
}












/* This is -*- C++ -*-  */
#include <gtk--.h>

//
// hello.cc
// This program doesn't crash with a segfault when creating the Color Selector,
// The only difference is that the Main window is made in its own class
// HelloWorld, and not just in main(). The class Colorbutton is just copied!
// Just press the  lower button!


GdkWindow * gdkmainwindow; // Awful global that I need for creating a pixmap
// when it's object still doesn't have a window

class ColorButton : public Gtk_Button {
public:
  ColorButton(gchar * label):Gtk_Button(){
    GdkWindow * win = GTK_WIDGET(gtkobject)->window;
    GtkStyle * style= GTK_WIDGET(gtkobject)->style;
    GtkWidget * widget =GTK_WIDGET(gtkobject);
  
    /*   pixmap = gdk_pixmap_create_from_xpm (gdkmainwindow, &mask,
      		                         &style->bg[GTK_STATE_NORMAL],
					 "3DRings.xpm");
      
    pix = new Gtk_Pixmap(pixmap,mask);
    pix->show();
    add(pix);
    pix->show();*/
  }
  ~ColorButton()
  {/* if (pix) delete pix;
    if (col_gc) gdk_gc_destroy(col_gc);
    gdk_pixmap_unref(pixmap);
    gdk_bitmap_unref(mask);*/

  }

void  test_cb()
  {
   
   if (!colorsel) colorsel = new Gtk_ColorSelectionDialog("Select color!");
   colorsel->show();
     }
    

private:
  //  GdkPixmap *pixmap;
  //  GdkBitmap *mask;
  //  GdkGC *col_gc=NULL;
  // Gtk_Pixmap *pix;
  Gtk_ColorSelectionDialog *colorsel;
};

//Unimportant class for the buggy behavior... 
class MyDraw : public Gtk_DrawingArea {

public: 
MyDraw();
gint expose_cb(GdkEventExpose *) { 
	GtkWidget *widget;    
	printf("Ouch...I'm exposed!\n"); 
    	widget = GTK_WIDGET(gtkobject);
	gdk_draw_rectangle(widget->window,
                            widget->style->white_gc,
                            TRUE,
                            0, 0,
                            widget->allocation.width,
                            widget->allocation.height);
	return 0;
  }
gint button_press_cb(GdkEventButton *) { 
    printf("Ouch...pressed!\n"); 
    return 0;
  }
gint motion_notify_cb(GdkEventMotion *) { 
    printf("Ouch...moved!\n");
    return 0; 
  }
/*gint button_press_cb2(GdkEventButton *) { 
    printf("Ouch...callback 2!\n"); 
    return 0;
  }*/  

};
MyDraw::MyDraw(){
  printf("set_events\n");
  set_events(GDK_EXPOSURE_MASK         
           | GDK_BUTTON_PRESS_MASK
           | GDK_POINTER_MOTION_MASK
           | GDK_POINTER_MOTION_HINT_MASK);
	connect(expose_event,this,&expose_cb);
	connect(button_press_event,this,&button_press_cb);
        connect(motion_notify_event,this,&motion_notify_cb);
     //   connect(button_press_event,this,&button_press_cb2);
}



class HelloWorld : public Gtk_Window { // (1)
   
  Gtk_Button b1,b2;
  ColorButton cbutton;
  Gtk_HBox hbox;
  Gtk_VBox vbox;
  MyDraw drw_area;
  void 	click_cb(int num){printf("Button %d clicked \n",num);};  
public:
  HelloWorld();
  
  /*gint delete_event_impl(GdkEventAny *) {
    printf("Ouch...I'm shot....Aahh!\n"); 
    Gtk_Main::instance()->quit(); 
    return 0;
  }*/
  
};

HelloWorld::HelloWorld():
    b1("Hello World"),b2("hi!"),cbutton("test"),
    hbox(true,0),vbox(true,0)
  {
    border_width(10);
    drw_area.set_usize(100,100);
    hbox.pack_start(&drw_area);
    vbox.pack_start(&b1);
    vbox.pack_start(&b2);
    vbox.pack_start( &cbutton);  
    hbox.pack_start(&vbox);
  
    //connect( b.clicked, Gtk_Main::instance(), &Gtk_Main::quit );
    connect( b1.clicked,this , &click_cb,1);
    connect( b2.clicked,this , &click_cb,2);
 connect(cbutton.clicked,&cbutton, &ColorButton::test_cb);
    cbutton.show();
    b1.show();
    b2.show();
    drw_area.show();
    vbox.show(); 
    hbox.show();
    add(&hbox); 
  }

int main( int argc, char **argv )
{
  Gtk_Main m( &argc, &argv ); 
  HelloWorld w; 
  
  //w.set_usize( 100,20 ); 
  w.show();
  
  m.run(); 
  return 0;
}














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