sdl2_frt/src
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
..
atomic atomic: Support compiling on ARMv3 2019-10-11 22:08:53 +01:00
audio Readability: remove redundant return, continue, enum declaration 2019-10-30 15:36:17 +01:00
core Android: some readability: redundant casts, deads stores, redundant control flow 2019-10-31 15:53:10 +01:00
cpuinfo Fix crash when detecting SIMD 2019-11-16 22:55:36 +01:00
dynapi ran gendynapi.pl after SDL_HasARMSIMD() addition 2019-11-04 11:15:24 +03:00
events Added a utility function to simplify the hint handling logic 2019-11-13 21:53:01 -08:00
file Readability: remove redundant cast to the same type 2019-10-30 15:13:55 +01:00
filesystem Readability: remove redundant cast to the same type 2019-10-30 15:13:55 +01:00
haptic
hidapi Prevent the SPEEDLINK COMPETITION PRO joystick from switching into Android controller mode when enumerated over HID on Windows 10. 2019-08-22 15:58:00 -07:00
joystick Don't try to use this driver with the Xbox One S in Bluetooth mode on Linux 2019-11-16 19:58:29 -08:00
libm Readability: change some pointer parameter to be pointer to const 2019-10-30 16:06:51 +01:00
loadso Readability: remove redundant cast 2019-10-30 16:20:58 +01:00
main haiku: mouse_relative fix 2019-11-11 22:23:33 -05:00
power SDL_syspower.c: remove redundant expression 2019-10-30 16:12:39 +01:00
render SDL_render_gles2: remove ineffective widening cast 2019-10-30 16:45:53 +01:00
sensor Fixed bug 4837 - Use after free in SDL_SensorUpdate (Thanks!) 2019-10-23 08:46:59 +02:00
stdlib SDL_qsort.c: sync comments with version 1.15 from mainstream 2019-10-31 17:10:02 +03:00
test Added SDL_PIXELFORMAT_BGR444 2019-11-02 22:58:52 +00:00
thread Remove redundant 'SDL_GetErrBuf' declaration 2019-10-30 17:35:40 +01:00
timer
video 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
SDL_assert_c.h
SDL_assert.c Readability: remove const-qualifation from function declaration 2019-10-30 15:43:49 +01:00
SDL_dataqueue.c
SDL_dataqueue.h
SDL_error_c.h
SDL_error.c Remove redundant 'SDL_GetErrBuf' declaration 2019-10-30 17:35:40 +01:00
SDL_hints_c.h Added a utility function to simplify the hint handling logic 2019-11-13 21:53:01 -08:00
SDL_hints.c Fix missing prototype warning 2019-11-16 22:59:56 +01:00
SDL_internal.h
SDL_log.c Copypaste SDL_NSLog to UIKit backend, document it as such 2019-07-17 23:20:57 -04:00
SDL.c Readability: remove const-qualifation from function declaration 2019-10-30 15:43:49 +01:00