[cairo] BadRequest and cairo_xlib_surface_create

Carl Worth cworth at cworth.org
Mon Aug 27 09:40:26 PDT 2007


On Mon, 27 Aug 2007 15:13:49 +0200, Tamas K Papp wrote:
> Sometimes when I try to create a Cairo surface on a pixmap with
> cairo_xlib_surface_create, I get a BadRequest error, typically of the
> form
>
>   X Error of failed request:  BadRequest (invalid request code or no such operation)
>   Major opcode of failed request:  0 ()

What that says is that the X client as sent a request with a major
opcode of 0, (which is not any core request, nor is it any extension
request).

Cairo itself never constructs any X requests manually, (instead
relying on Xlib or XCB to do that), so something is definitely going
wrong at some lower level.

Last week I ran into a problem that was manifesting itself the exact
same way. It turned out that in that case what was happening was that
during XCloseDisplay, Xlib would first clean up its state used for
representing the Render extension, (including freeing the structure
that stores the major opcode value for Render), and then it would call
cairo's close_display hooks which would then call into
XRenderFreePicture. And since Xlib had already cleaned up its Render
state: Boom!

The fix I committed for that bug was as follows:

	commit 9f4e6436496fe561aa124bb2b89e1c6711684d98
	Author: Carl Worth <cworth at cworth.org>
	Date:   Tue Aug 21 10:03:00 2007 -0700

    Ensure the Render extension is initialized before calling XESetCloseDisplay

    This avoids a potential crash from the Render extension being cleaned
    up during XCloseDisplay before the cairo CloseDisplay hook goes on to
    call into XRenderFreePicture.

This gets pretty chummy with the Xlib implementation by knowing that
it cleans things up during XCloseDisplay in LIFO order, so as long as
XRender is initialized before cairo registers its close_display hooks,
then cairo's hooks get called before the XRender cleanup.

Anyway, I don't know if that has anything to do with the problem
you're having, (but you might as well try with a recent checkout of
cairo including the above commit). And if your problem is distinct,
maybe the above will give you an idea of the kind of thing you could
be looking at.

For me, it was a bit of xtrace, gdb, head scratching, and code
exploration that found the problem, (and some help from Keith Packard
to verify my conclusions and to suggest the fix).

Good luck!

-Carl
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.cairographics.org/archives/cairo/attachments/20070827/1f149252/attachment.pgp 


More information about the cairo mailing list