Re: segmentation fault



Aaron Yang wrote:
> void draw_button_clicked ( void )
{
1. You're passing NULL as a parameter for timeout's callback.
  g_timeout_add (100, real_draw, NULL);
}
2. window parameter is NULL (see above).
static gint real_draw ( gpointer window )
{
  GtkWidget *widget;
3. Variable widget is undefined, it can hold any pointer.
  static int i=0;

4. Here you're passing undefined variable to the draw_brush call.
  draw_brush (widget, x[i], y[i]);
  i++;
  return TRUE;
}

Compile your program with -Wall gcc option and fix all warnings from compiler.

To solve your problem you should do smth like this:

void draw_button_clicked ( GtkWidget *button, GtkWidget *drawing_area )
{
  g_timeout_add (100, real_draw, drawing_area);
}

static gint real_draw ( GtkWidget *drawing_area )
{
  static int i=0;

  draw_brush (widget, x[i], y[i]);
  i++;
  return TRUE;
}

Somewhere in code:
g_signal_connect (button, "clicked", G_CALLBACK(draw_button_clicked), drawing_area);

        Olexiy




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