Discussion:
[cairo] zero size textures?
`VL
2017-12-12 21:44:06 UTC
Permalink
Hello,
I've faced with a bug in my application, when it stopped any drawing
(using cairo/xcb)
Investigation lead me to the following code snippet,
where dx, dy, dst->x, dst->y and dst->w, dst->h occurred to be all zeroes:

cairo_push_group(gc->cr);

/* commenting out this 3 lines avoids issues */
cairo_translate(gc->cr, dst->x, dst->y);                             
cairo_rectangle(gc->cr, 0, 0, dst->w, dst->h);                       
cairo_scale(gc->cr, dx, dy);

cairo_set_source_surface(gc->cr, CS(tspec->tx), 0, 0);

cairo_fill(gc->cr);                                                    
                                                                               

cairo_pop_group_to_source(gc->cr);        
                            
cairo_paint_with_alpha(gc->cr, tspec->alpha);        

The bad thing is that after calling this, cairo_text_extents()
starts returning zeroes instead of correct sizes, so it looks
like some memory inside library was corrupted.

So the question - is it ok to call cairo functions with zero sizes
and expect some valid result? Could it be some bug in cairo (xcb backend) ?

I'm using:
x11-libs/cairo-1.14.8
x11-libs/libxcb-1.12-r2
OS is Gentoo linux

Thanks in advance!
--
cairo mailing list
***@cairographics.org
https://lists.cairographics.org/mailman/listin
Uli Schlachter
2017-12-16 09:48:32 UTC
Permalink
Hi,
Post by `VL
Hello,
I've faced with a bug in my application, when it stopped any drawing
(using cairo/xcb)
Investigation lead me to the following code snippet,
[...]
Post by `VL
/* commenting out this 3 lines avoids issues */
cairo_translate(gc->cr, dst->x, dst->y);                             
cairo_rectangle(gc->cr, 0, 0, dst->w, dst->h);                       
cairo_scale(gc->cr, dx, dy);
[...]
Post by `VL
So the question - is it ok to call cairo functions with zero sizes
and expect some valid result? Could it be some bug in cairo (xcb backend) ?
Look at cairo_status() and/or cairo_surface_status(). Once an object
ends up in an error state, all operations in it will fail.

In your case, cairo_scale(cr, 0, 0) will cause a
CAIRO_STATUS_INVALID_MATRIX error.

Note that this is not specific to cairo-xcb, but is in the "generic
part" of cairo.

Cheers,
Uli
--
- Captain, I think I should tell you I've never
actually landed a starship before.
- That's all right, Lieutenant, neither have I.
--
cairo mailing list
***@cairographics.org
https://lists.cairographics.org/mailman/listinfo/cair
`VL
2017-12-16 15:18:12 UTC
Permalink
Post by Uli Schlachter
Hi,
Post by `VL
Hello,
I've faced with a bug in my application, when it stopped any drawing
(using cairo/xcb)
Investigation lead me to the following code snippet,
[...]
Post by `VL
/* commenting out this 3 lines avoids issues */
cairo_translate(gc->cr, dst->x, dst->y);                             
cairo_rectangle(gc->cr, 0, 0, dst->w, dst->h);                       
cairo_scale(gc->cr, dx, dy);
[...]
Post by `VL
So the question - is it ok to call cairo functions with zero sizes
and expect some valid result? Could it be some bug in cairo (xcb backend) ?
Look at cairo_status() and/or cairo_surface_status(). Once an object
ends up in an error state, all operations in it will fail.
ok, this explains why further rendering stops.
But I can't find a function to reset state and somehow rollback operation.
My app did all operations in a block of cairo_save/cairo_restore, but it
doesn't seem to help with error state.

Or am I supposed to re-create whole context on any error?
I.e. the pattern will be like:

create context
draw something with series of commands
check context status for CAIRO_STATUS_SUCCESS
If not ok, drop the context and start from scratch.
Post by Uli Schlachter
In your case, cairo_scale(cr, 0, 0) will cause a
CAIRO_STATUS_INVALID_MATRIX error.
yes, this is exactly what was happening.

Thank you very much for explaining all this.
Post by Uli Schlachter
Note that this is not specific to cairo-xcb, but is in the "generic
part" of cairo.
Cheers,
Uli
--
cairo mailing list
***@cairographics.or
Uli Schlachter
2017-12-16 17:48:26 UTC
Permalink
[...]
Post by `VL
Post by Uli Schlachter
Post by `VL
So the question - is it ok to call cairo functions with zero sizes
and expect some valid result? Could it be some bug in cairo (xcb backend) ?
Look at cairo_status() and/or cairo_surface_status(). Once an object
ends up in an error state, all operations in it will fail.
ok, this explains why further rendering stops.
But I can't find a function to reset state and somehow rollback operation.
My app did all operations in a block of cairo_save/cairo_restore, but it
doesn't seem to help with error state.
Or am I supposed to re-create whole context on any error?
[...]
I'm afraid that errors are sticky. I guess you are supposed not to cause
any, sorry.

Can't you check for a scale of zero before doing cairo_scale() and if
you see a zero there, you just skip the whole block of drawing operations?

Cheers,
Uli
--
- Captain, I think I should tell you I've never
actually landed a starship before.
- That's all right, Lieutenant, neither have I.
--
cairo mailing list
***@cairographics.org
https://lists.cairographics.org/m
`VL
2017-12-16 18:26:26 UTC
Permalink
Post by Uli Schlachter
[...]
Post by `VL
Post by Uli Schlachter
Post by `VL
So the question - is it ok to call cairo functions with zero sizes
and expect some valid result? Could it be some bug in cairo (xcb backend) ?
Look at cairo_status() and/or cairo_surface_status(). Once an object
ends up in an error state, all operations in it will fail.
ok, this explains why further rendering stops.
But I can't find a function to reset state and somehow rollback operation.
My app did all operations in a block of cairo_save/cairo_restore, but it
doesn't seem to help with error state.
Or am I supposed to re-create whole context on any error?
[...]
I'm afraid that errors are sticky. I guess you are supposed not to cause
any, sorry.
Can't you check for a scale of zero before doing cairo_scale() and if
you see a zero there, you just skip the whole block of drawing operations?
yes, of course. This is what I'm doing now to avoid bad call.
I think it's worth to improve documentation: particularly cairo_scale()
doesn't mention which parameters are accepted, and which would lead
to incorrect context.
Post by Uli Schlachter
Cheers,
Uli
--
cairo mailing list
***@cairographics.org
https://lists.cairographics.org/mailman/l
Bryce Harrington
2018-01-05 01:56:19 UTC
Permalink
Post by `VL
Post by Uli Schlachter
[...]
Post by `VL
Post by Uli Schlachter
Post by `VL
So the question - is it ok to call cairo functions with zero sizes
and expect some valid result? Could it be some bug in cairo (xcb backend) ?
Look at cairo_status() and/or cairo_surface_status(). Once an object
ends up in an error state, all operations in it will fail.
ok, this explains why further rendering stops.
But I can't find a function to reset state and somehow rollback operation.
My app did all operations in a block of cairo_save/cairo_restore, but it
doesn't seem to help with error state.
Or am I supposed to re-create whole context on any error?
[...]
I'm afraid that errors are sticky. I guess you are supposed not to cause
any, sorry.
Can't you check for a scale of zero before doing cairo_scale() and if
you see a zero there, you just skip the whole block of drawing operations?
yes, of course. This is what I'm doing now to avoid bad call.
I think it's worth to improve documentation: particularly cairo_scale()
doesn't mention which parameters are accepted, and which would lead
to incorrect context.
Good idea, would you mind suggesting a revised text phrasing?

Bryce
--
cairo mailing list
***@cairographics.org
https
Loading...