same cairo graphics context in multiple methods

Let's say I have a class which extends DrawingArea, and in the class, I have

Cairo::RefPtr<Cairo::Context> gfx;

and in a method of the class (I do this in: on_expose_event), I instantiate


Now, I want to use that specific graphics context in other methods (all
within the same scope as gfx). This doesn't seem to be a problem (i.e. the
context collects the data I give it) until I call gfx->stroke(); at which
point my program crashes, with this error:
glibmm-ERROR **: 
unhandled exception (type std::exception) in signal handler:
what: <unknown error status>

For example, the following method generates an error when it's run the
second time (the same method being run a second time might as well be a
different method - the result is the same, anyway):
bool Canvas::on_expose_event(GdkEventExpose * event)
	//get dimensions
	Gtk::Allocation allocation = get_allocation();
	int width = allocation.get_width();
	int height = allocation.get_height();
	gfx = this->get_window()->create_cairo_context();
	std::cout<<"creating new graphics context\n";
	//white rectangle
	gfx->set_source_rgb(1.0, 1.0, 1.0);
	gfx->line_to(0.0, height);
	gfx->line_to(width, height);
	gfx->line_to(width, 0.0);

Is what I'm trying even possible or am I going to have to generate a new
graphics context and stroke() for every method?
View this message in context:
Sent from the Gtkmm mailing list archive at

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