[cairo] Unable to paint on Gtk drawing_area with Cairo

Gurjot Singh bhattigurjot at gmail.com
Fri Aug 1 02:14:02 PDT 2014


Hi,

I am trying to paint a point on drawing_area in Gtk with cairo. I have
two functions, do_drawing function to paint the background on draw
signal, and the second one do_drawPointto draw a point.

void painter::do_drawing(cairo_t *cr)
{
cairo_set_source_rgb(cr, 1, 1, 1);
cairo_paint(cr);
}

void painter::do_pointDraw(cairo_t *cr)
{
cairo_set_source_rgb(cr, 0, 0, 0);
cairo_arc(cr, 150, 150, 10, 0, 2 * M_PI);
cairo_fill(cr);
}

Now, the drawPoint function is called whenever user clicks on the drawing_area.

void drawingArea::drawPoint()
{
g_signal_connect(area, "button-press-event",
  G_CALLBACK(clicked), NULL);
std::cout<<"drawPoint"<<std::endl;
}

gboolean clicked(GtkWidget *widget, GdkEventButton *event, cairo_t *cr,
gpointer user_data)
{
if (event->button == 1) {
    x = event->x;
    y = event->y;
}
std::cout<<x<<" and "<<y<<std::endl;
ptr->do_pointDraw(cr);
gtk_widget_queue_draw(widget);
}
return TRUE;
}

But after printing values of x and y, the program terminates with
segmentation fault.

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff74ac3ae in cairo_set_source_rgb ()

What might be causing this? Am I proceeding correctly?


-- 
Gurjot Singh
Blog: http://bhattigurjot.wordpress.com

"It takes a person who is wide awake to make his dream come true." ~
Roger Babson


More information about the cairo mailing list