Bug 33758 - CreateDRIDrawable can't fail gracefully
Summary: CreateDRIDrawable can't fail gracefully
Alias: None
Product: Mesa
Classification: Unclassified
Component: GLX (show other bugs)
Version: git
Hardware: All All
: medium normal
Assignee: mesa-dev
QA Contact:
Depends on:
Reported: 2011-01-31 06:05 UTC by nobled
Modified: 2019-09-18 17:36 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:

small EGL program to produce BadDrawable error (2.31 KB, text/plain)
2011-06-27 12:58 UTC, nobled

Description nobled 2011-01-31 06:05:34 UTC
(I'm running on Ubuntu 10.04 x86-32 with mesa from the 7.10 Natty package, just for the record - but this bug is also in git and older versions.)

In src/glx/glx_pbuffer.c, CreateDRIDrawable can fail, in which case it prints "failed to create drawable", but the caller has no way of knowing that it failed at all and just keeps going.

Whenever I called eglCreatePbuffer, "failed to create drawable" gets printed (not sure why - because Ubuntu 10.04 has a slightly older X server?), but I got a seemingly valid EGLSurface anyway. And when I tried to use it in eglMakeCurrent(), I get a mysterious segfault:

Breakpoint 4, GLX_eglMakeCurrent (drv=0x80ec2e0, disp=0x80eb680, 
    dsurf=0x8164370, rsurf=0x8164370, ctx=0x816ed10) at egl_glx.c:738
(gdb) next
760	      ret = GLX_drv->glXMakeCurrent(GLX_dpy->dpy, ddraw, cctx);
(gdb) next

Program received signal SIGSEGV, Segmentation fault.
0x00434e18 in ?? () from /usr/lib/mesa/libGL.so.1
(gdb) bt
#0  0x00434e18 in ?? () from /usr/lib/mesa/libGL.so.1
#1  0x004356a7 in ?? () from /usr/lib/mesa/libGL.so.1
#2  0x004346f2 in ?? () from /usr/lib/mesa/libGL.so.1
#3  0x00412c3f in glXMakeCurrentReadSGI () from /usr/lib/mesa/libGL.so.1
#4  0x00412dd3 in glXMakeCurrent () from /usr/lib/mesa/libGL.so.1
#5  0x00462e8c in GLX_eglMakeCurrent (drv=0x80ec2e0, disp=0x80eb680, 
    dsurf=0x8164370, rsurf=0x8164370, ctx=0x816ed10) at egl_glx.c:760
#6  0x00454f8f in eglMakeCurrent (dpy=0x80eb680, draw=0x8164370, 
    read=0x8164370, ctx=0x816ed10) at eglapi.c:478
Comment 1 nobled 2011-01-31 06:26:26 UTC
It looks like the same problem is also in glxcmds.c:glXCreateGLXPixmap (it returns the same xid whether or not driScreen->createDrawable() returned null)
Comment 2 nobled 2011-01-31 16:50:38 UTC
Okay, with debug symbols now the backtrace is:

#0  0x00434e18 in XCreateDrawable (base=0x811caa0, xDrawable=102760449, 
    drawable=102760449, modes=0x8170ff0) at drisw_glx.c:94
#1  driCreateDrawable (base=0x811caa0, xDrawable=102760449, 
    drawable=102760449, modes=0x8170ff0) at drisw_glx.c:377
#2  0x004356a7 in driFetchDrawable (gc=0x8167468, glxDrawable=102760449)
    at dri_common.c:373
#3  0x004346f2 in drisw_bind_context (context=0x8167468, old=0x44a1c0, 
    draw=102760449, read=102760449) at drisw_glx.c:266
#4  0x00412c3f in MakeContextCurrent (dpy=0x81400c0, draw=102760449, 
    read=102760449, gc_user=0x8167468) at glxcurrent.c:263
#5  0x00412dd3 in glXMakeCurrent (dpy=0x81400c0, draw=102760449, gc=0x8167468)
    at glxcurrent.c:287
#6  0x00462e8c in GLX_eglMakeCurrent (drv=0x80ec2e0, disp=0x80eb680, 
    dsurf=0x8164370, rsurf=0x8164370, ctx=0x816ed10) at egl_glx.c:760
#7  0x00454f8f in eglMakeCurrent (dpy=0x80eb680, draw=0x8164370, 
    read=0x8164370, ctx=0x816ed10) at eglapi.c:478

XGetVisualInfo() returned null, and that doesn't get checked for.
Comment 3 nobled 2011-06-24 18:29:49 UTC
This patch by ajax back in May seems relevant, BTW. I'll test it (and Chad's patches) when I get a chance.

Comment 4 nobled 2011-06-27 12:53:00 UTC
Good news and bad news.

Good news: I tested in an Ubuntu Maverick chroot, and I can't reproduce the segfault -- maybe it was fixed in Xlib? (In Lucid, libX11 is version 1.3.2; in Maverick, it's 1.3.3) Now, instead of silently segfaulting, it seems to call exit(1) after giving a much more informative printout. Which is a *very slight* improvement:

(gdb) finish
Run till exit from #0  drisw_bind_context (context=0x80690b0, old=0x4871e0, 
    draw=106954753, read=106954753) at drisw_glx.c:267
X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)
  Major opcode of failed request:  55 (X_CreateGC)
  Resource id in failed request:  0x6600001
  Serial number of failed request:  26
  Current serial number in output stream:  28

Program exited with code 01.
(gdb) quit

Bad news is, ajax's patch no longer applies cleanly to master <773556e0f537eba82d9d68d618e229140f413620>, and I tested both of Chad's patches and the bug still happens.

I'll attach a reduced testcase.
Comment 5 nobled 2011-06-27 12:58:05 UTC
Created attachment 48483 [details]
small EGL program to produce BadDrawable error

(Unrelatedly, I had to workaround another bug in the egl_glx driver by commenting out the EGL_RENDERABLE_TYPE line: otherwise, it failed to create the EGLSurface at all because it didn't recognize it: "libEGL warning: bad surface attribute 0x3040")
Comment 6 GitLab Migration User 2019-09-18 17:36:29 UTC
-- GitLab Migration Automatic Message --

This bug has been migrated to freedesktop.org's GitLab instance and has been closed from further activity.

You can subscribe and participate further through the new bug through this link to our GitLab instance: https://gitlab.freedesktop.org/mesa/mesa/issues/72.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.