[cairo] Proper invocation of cairo_clip()?

Bob Jamison rjamison at titan.com
Tue Mar 15 10:39:15 PST 2005


Hi, all.

I have been wondering how to properly call cairo_clip().
Maybe someone could tell me what dumb mistake I am making.
Here is where I want to grab a rect from the drawing area,
and move it to 0,0, coding it similarly to test/clip-twice.c.
It -seems- simple enough:


    cairo_save(cairo);
    //clip and move to 0,0
    cairo_new_path(cairo);
    cairo_rectangle(cairo, x, y, width, height);
    cairo_clip(cairo);
    cairo_translate(cairo, -x, -y);
    //do my drawing
    cairo_restore(cairo);

It is segfaulting with:

Program received signal SIGSEGV, Segmentation fault.
0x0805fc4a in _cairo_xlib_surface_composite_trapezoids (
    operator=CAIRO_OPERATOR_IN, pattern=0xfef78574, abstract_dst=0x8ffc358,
    src_x=0, src_y=0, dst_x=0, dst_y=0, width=1, height=1, traps=0x0,
    num_traps=0) at cairo/src/cairo_xlib_surface.c:752
752         if (traps[0].left.p1.y < traps[0].left.p2.y) {
Current language:  auto; currently c
(gdb) bt
#0  0x0805fc4a in _cairo_xlib_surface_composite_trapezoids (
    operator=CAIRO_OPERATOR_IN, pattern=0xfef78574, abstract_dst=0x8ffc358,
    src_x=0, src_y=0, dst_x=0, dst_y=0, width=1, height=1, traps=0x0,
    num_traps=0) at cairo/src/cairo_xlib_surface.c:752
#1  0x0805afe7 in _cairo_surface_composite_trapezoids (
    operator=CAIRO_OPERATOR_IN, pattern=0xfef78574, dst=0x8ffc358, src_x=0,
    src_y=0, dst_x=0, dst_y=0, width=1, height=1, traps=0x0, num_traps=0)
    at cairo/src/cairo_surface.c:766
#2  0x080541b6 in _cairo_gstate_clip (gstate=0x8ffbfb0)
    at cairo/src/cairo_gstate.c:1915
#3  0x0804fc74 in cairo_clip (cr=0x8ff6af8) at cairo/src/cairo.c:1098




Notice that traps==NULL.

Other code can draw nicely with the cairo_t* context before this code.

Am I doing this correctly?



Thanks,
Bob Jamison




More information about the cairo mailing list