Fixed bug 3770 - XStoreColor returns zero on failure SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sun, 27 Aug 2017 19:03:15 -0700
branchSDL-1.2
changeset 11362464908ca2d22
parent 11056 1138bf8c009a
child 11389 2c67e7e5a106
Fixed bug 3770 - XStoreColor returns zero on failure

Thorsten Otto

The fix done in http://hg.libsdl.org/SDL/rev/3665bc284271 is wrong. The current code returns -1 if the calls *succeeds*, and does not call XSync(). The outcome of this is that the whole screen turns black when trying to open a 640x480x8 window on a true-color display (short example attached). I suggest to add the attached patch to fix this (yes i know that the 1.2 branch is obsolete, but the faulty patch causes really bad behaviour for a very common scenario).
src/video/x11/SDL_x11video.c
     1.1 --- a/src/video/x11/SDL_x11video.c	Thu Jun 01 00:39:07 2017 -0400
     1.2 +++ b/src/video/x11/SDL_x11video.c	Sun Aug 27 19:03:15 2017 -0700
     1.3 @@ -1462,7 +1462,7 @@
     1.4  
     1.5  int X11_SetGammaRamp(_THIS, Uint16 *ramp)
     1.6  {
     1.7 -	int i, ncolors;
     1.8 +	int i, result, ncolors;
     1.9  	XColor xcmap[256];
    1.10  
    1.11  	/* See if actually setting the gamma is supported */
    1.12 @@ -1481,12 +1481,13 @@
    1.13  		xcmap[i].blue  = ramp[2*256+c];
    1.14  		xcmap[i].flags = (DoRed|DoGreen|DoBlue);
    1.15  	}
    1.16 -	if ( XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors) != 0 ) {
    1.17 +	result = 0;
    1.18 +	if ( XStoreColors(GFX_Display, SDL_XColorMap, xcmap, ncolors) == False ) {
    1.19  		SDL_SetError("Setting gamma correction failed");
    1.20 -		return(-1);
    1.21 +		result = -1;
    1.22  	}
    1.23  	XSync(GFX_Display, False);
    1.24 -	return(0);
    1.25 +	return result;
    1.26  }
    1.27  
    1.28  /* Note:  If we are terminated, this could be called in the middle of