Unable to paint on Gtk drawing_area with Cairo

Gurjot Singh <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <CANWseAZ54Pa_pbcBW9-qo_H98xBaaaS5MT9GgokEysVtt00f4g@mail.gmail.com>
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
-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.