[cairo] BadRequest and cairo_xlib_surface_create

Tamas K Papp tpapp at Princeton.EDU
Wed Sep 5 02:36:37 PDT 2007

On Mon, Aug 27, 2007 at 09:40:26AM -0700, Carl Worth wrote:
> 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).

Thanks Carl,

I think it was the same bug, downloading the latest version in git
fixes the problem and now it works like a charm (at least I hope so,
stress tests of opening/closing 100 windows in random order and doing
this many times run fine).

When should we expect a release which contains this fix?  I am going
to tell cl-cairo2 users to use the latest source form git, but I also
had to compile libpixman so I guess many people would prefer to wait
for the deb package.


More information about the cairo mailing list