Re: What's wrong with my button callback



On Thu, Jun 29, 2006 at 07:49:43PM +1000, kadil wrote:
I used glade to "build" some a simple app. Why does my
on_button1_clicked callback segfault. The very same function call works
in the expose event.

Nothing in on_drawingarea1_expose_event() uses the
global variable drawingarea1, so they are not quite the
same.  It's probably uninitialized when on_button1_clicked()
is called (note global variables are generally frowned upon,
you can easily attach the pixmap to the drawing area with
g_object_set_data() and also pass the drawing area as the
callback data of on_button1_clicked() completely eliminating
global variables).

Did you try to use a debugger before mailing to the list?
Or valgrind?  What did you find?  If the cause really is
uninitialized drawingarea1, you would find it very easily
yourself.


#ifdef HAVE_CONFIG_H
#  include <config.h>
#endif

#include <gtk/gtk.h>

#include "callbacks.h"
#include "interface.h"
#include "support.h"
static GdkPixmap *pixmap = NULL;
GtkWidget *drawingarea1;

void
on_button1_clicked                     (GtkButton       *button,
                                        gpointer         user_data)
{ 
 
      gdk_draw_rectangle(pixmap, drawingarea1->style->black_gc,TRUE,50,
50,99, 88);
 
}

gboolean
on_drawingarea1_expose_event           (GtkWidget       *widget,
                                        GdkEventExpose  *event,
                                        gpointer         user_data)
{
gdk_draw_drawable(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE
(widget)], pixmap,  event->area.x, event->area.y,  event->area.x,
event->area.y, event->area.width, event->area.height);
  return FALSE;
}

Yeti


--
Anonyms eat their boogers.



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