From d3a21abd0f227c238cd0c2cd55e34e578c52d4fb Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Fri, 8 Feb 2008 23:13:39 -0500 Subject: [PATCH] grab the server while getting the pixmap for the window, and make sure the window is still valid first --- loco/loco.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/loco/loco.c b/loco/loco.c index 29a2b300..b28f4ef7 100644 --- a/loco/loco.c +++ b/loco/loco.c @@ -125,10 +125,17 @@ static void timeadd(GTimeVal *t, glong microseconds) } } +static Bool look_for_destroy_notify(Display *d, XEvent *e, XPointer arg) +{ + const Window w = (Window)*arg; + return e->type == DestroyNotify && e->xdestroywindow.window == w; +} + gboolean create_glxpixmap(LocoWindow *lw) { static const int attrs[] = { GLX_TEXTURE_FORMAT_EXT, GLX_TEXTURE_FORMAT_RGBA_EXT, None }; + XEvent ce; if (!glxFBConfig[lw->depth]) { printf("no glxFBConfig for depth %d for window 0x%lx\n", @@ -136,14 +143,25 @@ gboolean create_glxpixmap(LocoWindow *lw) return FALSE; } - lw->pixmap = XCompositeNameWindowPixmap(obt_display, lw->id); - lw->glpixmap = glXCreatePixmap(obt_display, glxFBConfig[lw->depth], - lw->pixmap, attrs); - if (!lw->glpixmap) { - XFreePixmap(obt_display, lw->pixmap); - lw->pixmap = None; + /* make sure the window exists */ + XGrabServer(obt_display); + XSync(obt_display, FALSE); + + if (!XCheckIfEvent(obt_display, &ce, look_for_destroy_notify, + (XPointer)&lw->id)) + { + lw->pixmap = XCompositeNameWindowPixmap(obt_display, lw->id); + lw->glpixmap = glXCreatePixmap(obt_display, glxFBConfig[lw->depth], + lw->pixmap, attrs); + if (!lw->glpixmap) { + XFreePixmap(obt_display, lw->pixmap); + lw->pixmap = None; + } } + XUngrabServer(obt_display); + XFlush(obt_display); + return !!lw->glpixmap; } -- 2.39.2