sdl2_frt/src/video
Sam Lantinga b1539c4c49 Fixed bug 4819 - Attempting to create an OpenGL ES context with unachievable MSAA parameters under X11 dooms the program
Solra Bizna

I have written a program that, in the event that the user requests more MSAA samples than their hardware supports, attempts to gracefully fall back to the best MSAA available. This code works with my conventional OpenGL renderer, but if I change nothing about the code except to make it request an OpenGL ES profile instead, Xlib kills the program with an error that looks like:

X Error of failed request:  BadWindow (invalid Window parameter)
  Major opcode of failed request:  4 (X_DestroyWindow)
  Resource id in failed request:  0x5c00008
  Serial number of failed request:  188
  Current serial number in output stream:  193

To trigger the bug, attempt to create a window with the SDL_WINDOW_OPENGL flag, with SDL_GL_CONTEXT_PROFILE_MASK set to SDL_GL_CONTEXT_PROFILE_ES, and with SDL_GL_MULTISAMPLESAMPLES set to any unsupported value. SDL_CreateWindow properly returns NULL, but at this point the program is already doomed. Xlib will shortly terminate the program with an error. Calling SDL_CreateWindow again will immediately trigger this termination.

I have attached a skeletal program that reproduces this bug for me. Replacing SDL_GL_CONTEXT_PROFILE_ES with SDL_GL_CONTEXT_PROFILE_COMPATIBILITY avoids the bug (but, obviously, doesn't create an OpenGL ES context).

As I suspected, the problem was with XDestroyWindow being called twice on the same window. The X11_CreateWindow function in src/video/x11/SDL_x11window.c calls SetupWindowData. If initialization fails after that point, XDestroyWindow gets called on the window by a subsequent call to X11_DestroyWindow. But, later in the same function, iff a GLES context is requested and initializing it fails, X11_XDestroyWindow (which wraps XDestroyWindow) is manually called. Shortly after, the intended call to X11_DestroyWindow occurs, which attempts to destroy the same window again. Boom.

(The above confusing summary involves three separate, similarly-named functions: XDestroyWindow, X11_DestroyWindow, X11_XDestroyWindow)

I have attached a simple patch that removes the redundant X11_XDestroyWindow calls. I've tested that XDestroyWindow still gets called for the windows in question, and that it only gets called once.
2019-11-16 22:35:48 -08:00
..
android Android: some readability: redundant casts, deads stores, redundant control flow 2019-10-31 15:53:10 +01:00
arm ARM: NEON assembly optimization for SDL_FillRect 2019-10-24 21:17:52 -04:00
cocoa macOS: more robust detection and switching of exclusive-fullscreen display modes (bug #4822). 2019-10-26 15:27:51 -03:00
directfb use SDL_zeroa at more places where the argument is an array. 2019-07-31 05:11:40 +03:00
dummy Updated copyright for 2019 2019-01-04 22:01:14 -08:00
emscripten Add a windowID field to SDL_TouchFingerEvent (bug #4331). 2019-08-01 18:22:12 -03:00
haiku haiku: Rename BE_* entities to HAIKU_* 2019-11-12 17:24:37 -05:00
khronos Added Vulkan headers version 1.1.91 2018-11-06 16:57:07 -08:00
kmsdrm KMSDRM_GLES_SwapWindow: fix non-vsync case 2019-09-06 08:44:46 -07:00
nacl Updated copyright for 2019 2019-01-04 22:01:14 -08:00
offscreen offscreen: Add new video driver backend Offscreen 2019-09-24 16:36:48 -04:00
pandora Updated copyright for 2019 2019-01-04 22:01:14 -08:00
psp Updated copyright for 2019 2019-01-04 22:01:14 -08:00
qnx Fixed mingw Windows build, since SDL_vulkan_internal.h includes windows.h 2017-08-28 00:43:14 -07:00
raspberry RPI_FreeCursor: set global_cursor to NULL to prevent double-free (bug 4769) 2019-08-26 18:41:40 +03:00
uikit iOS: remove some unused code, minor code style cleanup. 2019-10-27 11:41:48 -03:00
vivante video: Add Vulkan support for vivante fb 2019-05-19 10:36:44 -07:00
wayland Wayland: touch events, use of memory after it is freed 2019-10-30 21:12:36 +01:00
windows Fixed bug 4840 - Read of uninitialized memory in DXGI_LoadDLL (Thanks!) 2019-10-23 09:26:27 +02:00
winrt WinRT: fix a link-time error when building UWP + x64 2019-10-02 14:55:02 -04:00
x11 Fixed bug 4819 - Attempting to create an OpenGL ES context with unachievable MSAA parameters under X11 dooms the program 2019-11-16 22:35:48 -08:00
yuv2rgb yuv: Patched to make static analysis happy (warned about unused variable). 2018-06-25 13:14:52 -04:00
SDL_blit_0.c Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_blit_1.c Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_blit_A.c ARM: NEON assembly optimization for function BlitARGBto565PixelAlpha 2019-10-24 21:17:38 -04:00
SDL_blit_auto.c BlitAuto: remove redundant cast to the same type 2019-10-30 14:37:06 +01:00
SDL_blit_auto.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_blit_copy.c Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_blit_copy.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_blit_N.c Readability: remove redundant return, continue, enum declaration 2019-10-30 15:36:17 +01:00
SDL_blit_slow.c Readability: remove redundant cast to the same type 2019-10-30 15:13:55 +01:00
SDL_blit_slow.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_blit.c Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_blit.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_bmp.c SDL_bmp.c: remove unused variable warnings 2019-09-05 10:08:47 +02:00
SDL_clipboard.c Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_egl_c.h offscreen: Avoid using EGLDeviceEXT as it causes issues with older platforms, which is just a void* 2019-09-24 17:27:51 -04:00
SDL_egl.c Android: remove eglGetProcAdded busted comment (bug #4040) 2019-10-23 11:07:11 +02:00
SDL_fillrect.c Use fill_function for FillRect SIMD/NEON (bug 4365) 2019-10-29 16:13:41 +01:00
SDL_pixels_c.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_pixels.c Added SDL_PIXELFORMAT_BGR444 2019-11-02 22:58:52 +00:00
SDL_rect_c.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_rect.c Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_RLEaccel_c.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_RLEaccel.c Fix const warning in RLE getpix functions 2019-10-30 16:17:59 +01:00
SDL_shape_internals.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_shape.c Readability: remove redundant cast to the same type 2019-10-30 15:13:55 +01:00
SDL_stretch.c Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_surface.c Fixed whitespace 2019-10-18 08:56:54 -07:00
SDL_sysvideo.h offscreen: Add new video driver backend Offscreen 2019-09-24 16:36:48 -04:00
SDL_video.c haiku: Rename BE_* entities to HAIKU_* 2019-11-12 17:24:37 -05:00
SDL_vulkan_internal.h video: Add Vulkan support for vivante fb 2019-05-19 10:36:44 -07:00
SDL_vulkan_utils.c vulkan: Fixed use-after-free bug. 2019-06-12 15:37:07 -04:00
SDL_yuv_c.h Updated copyright for 2019 2019-01-04 22:01:14 -08:00
SDL_yuv.c Android: minor warning 2019-08-30 09:00:06 +02:00
sdlgenblit.pl BlitAuto: remove redundant cast to the same type 2019-10-30 14:37:06 +01:00