[cairo] On recovery from errors in cairo (was: cairo reset)

Behdad Esfahbod behdad at behdad.org
Fri Sep 22 11:23:17 PDT 2006

On Fri, 2006-09-22 at 13:33 -0400, Carl Worth wrote:
> 1. If cairo considers something an error where it could instead behave
>    in a way that is consistent with the defined semantics of the API,
>    then this is a bug that should just be fixed in cairo.
>    Example: Imagine cairo_fill is setting an error when there is no
>    path set. The defined semantics of an empty path are quite clearly
>    that cairo should draw nothing, so it should just do that and not
>    set the error.

Well, I wouldn't call it quite clearly :-).  One may expect it to do an
unbounded fill, like cairo_paint does.  But I agree that what you
describe is in line with the define semantics and it should be done that

> 2. If the user is asks cairo to do something that has no reasonable
>    interpretation, then it is legitimate for cairo to set a permanent
>    error.
>    Example: Calling cairo_transform with a non-invertible matrix puts
>    cairo in a situation where it cannot continue and implement the
>    defined semantics of cairo_transform. So cairo will set an error in
>    this case.

This very specific one has caught me bad.  In my case, it was
cairo_scale (cr, 0, 0).  I argue that this shouldn't put the context in
an error state:

  cairo_save (cr);
  cairo_scale (cr, 0, 0);
  cairo_restore (cr);

but it currently does.  It shouldn't because:

  1) No other value in cairo_scale causes an error state, and so having
all infinitesimal values work as expected but zero not working is

  2) Scaling to zero *is* well-defined afterall!

  3) The error is in fact caused by internal implementation details of
cairo that requires an invertible matrix.  If the matrix is not
invertible, the only operations that are not well-defined are
cairo_device_to_user() and cairo_device_to_user_distance().  We can
possibly change those two to return an status instead of the current
void, or, to not change API, make those calls put the cairo_t in an
error state if the matrix is not invertible.


"Commandment Three says Do Not Kill, Amendment Two says Blood Will Spill"
        -- Dan Bern, "New American Language"

More information about the cairo mailing list