Catch X11 extension errors...since most of these are notifications that we
authorRyan C. Gordon <icculus@icculus.org>
Sat, 14 Jan 2006 08:15:38 +0000
changeset 1248d2c6881935be
parent 1247 ff73ee89ff4b
child 1249 e6a82dcdce09
Catch X11 extension errors...since most of these are notifications that we
queried for a missing extension (such as the XiG vidmode one that most
people don't have), and default Xlib behaviour is to write notification to
stderr, this tends to generate incorrect bug reports.

Since we'll actually deal with the missing extension when querying for it,
we ignore these errors in our hook. The rest continue to pass through to
the default handler.

Fixes Bugzilla #42.

--ryan.
src/video/x11/SDL_x11dyn.h
src/video/x11/SDL_x11sym.h
src/video/x11/SDL_x11video.c
     1.1 --- a/src/video/x11/SDL_x11dyn.h	Fri Jan 13 02:36:35 2006 +0000
     1.2 +++ b/src/video/x11/SDL_x11dyn.h	Sat Jan 14 08:15:38 2006 +0000
     1.3 @@ -57,6 +57,7 @@
     1.4  typedef Bool (*SDL_X11_XESetWireToEventRetType)(Display*,XEvent*,xEvent*);
     1.5  typedef int (*SDL_X11_XSynchronizeRetType)(Display*);
     1.6  typedef Status (*SDL_X11_XESetEventToWireRetType)(Display*,XEvent*,xEvent*);
     1.7 +typedef int (*SDL_X11_XSetExtensionErrorHandlerType)(Display *,char *,char *);
     1.8  
     1.9  #define SDL_X11_SYM(req,ret,fn,params) extern ret (*p##fn) params;
    1.10  #include "SDL_x11sym.h"
     2.1 --- a/src/video/x11/SDL_x11sym.h	Fri Jan 13 02:36:35 2006 +0000
     2.2 +++ b/src/video/x11/SDL_x11sym.h	Sat Jan 14 08:15:38 2006 +0000
     2.3 @@ -113,6 +113,8 @@
     2.4  SDL_X11_SYM(1,XExtDisplayInfo*,XextFindDisplay,(XExtensionInfo*,Display*))
     2.5  SDL_X11_SYM(1,int,XextRemoveDisplay,(XExtensionInfo*,Display*))
     2.6  SDL_X11_SYM(1,Bool,XQueryExtension,(Display*,_Xconst char*,int*,int*,int*))
     2.7 +SDL_X11_SYM(1,char *,XDisplayString,(Display*))
     2.8 +SDL_X11_SYM(1,int,XGetErrorText,(Display*,int,char*,int))
     2.9  
    2.10  #ifdef X_HAVE_UTF8_STRING
    2.11  SDL_X11_SYM(1,int,Xutf8TextListToTextProperty,(Display*,char**,int,XICCEncodingStyle,XTextProperty*))
    2.12 @@ -159,6 +161,7 @@
    2.13  SDL_X11_SYM(1,SDL_X11_XSynchronizeRetType,XSynchronize,(Display*,Bool))
    2.14  SDL_X11_SYM(1,SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display*,int,SDL_X11_XESetWireToEventRetType))
    2.15  SDL_X11_SYM(1,SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display*,int,SDL_X11_XESetEventToWireRetType))
    2.16 +SDL_X11_SYM(1,SDL_X11_XSetExtensionErrorHandlerType,XSetExtensionErrorHandler,(SDL_X11_XSetExtensionErrorHandlerType))
    2.17  
    2.18  /* end of SDL_x11sym.h ... */
    2.19  
     3.1 --- a/src/video/x11/SDL_x11video.c	Fri Jan 13 02:36:35 2006 +0000
     3.2 +++ b/src/video/x11/SDL_x11video.c	Sat Jan 14 08:15:38 2006 +0000
     3.3 @@ -220,7 +220,7 @@
     3.4  	       (e->error_code <= (vm_error+XF86VidModeNumberErrors)))) ) {
     3.5  #ifdef XFREE86_DEBUG
     3.6  { char errmsg[1024];
     3.7 -  XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
     3.8 +  pXGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
     3.9  printf("VidMode error: %s\n", errmsg);
    3.10  }
    3.11  #endif
    3.12 @@ -235,7 +235,7 @@
    3.13  	      (e->error_code <= (dga_error+XF86DGANumberErrors))) ) {
    3.14  #ifdef XFREE86_DEBUG
    3.15  { char errmsg[1024];
    3.16 -  XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
    3.17 +  pXGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
    3.18  printf("DGA error: %s\n", errmsg);
    3.19  }
    3.20  #endif
    3.21 @@ -262,6 +262,28 @@
    3.22  	return(XIO_handler(d));
    3.23  }
    3.24  
    3.25 +static int (*Xext_handler)(Display *,char *,char *) = NULL;
    3.26 +static int xext_errhandler(Display *d, char *ext_name, char *reason)
    3.27 +{
    3.28 +#ifdef XFREE86_DEBUG
    3.29 +	printf("Xext error inside SDL (may be harmless):\n");
    3.30 +	printf("  Extension \"%s\" %s on display \"%s\".\n",
    3.31 +	       ext_name, reason, pXDisplayString(d));
    3.32 +#endif
    3.33 +
    3.34 +	if (strcmp(reason, "missing") == 0) {
    3.35 +		/*
    3.36 +		 * Since the query itself, elsewhere, can handle a missing extension
    3.37 +		 *  and the default behaviour in Xlib is to write to stderr, which
    3.38 +		 *  generates unnecessary bug reports, we just ignore these.
    3.39 +		 */
    3.40 +		return 0;
    3.41 +	}
    3.42 +
    3.43 +	/* Everything else goes to the default handler... */
    3.44 +	return Xext_handler(d, ext_name, reason);
    3.45 +}
    3.46 +
    3.47  /* Create auxiliary (toplevel) windows with the current visual */
    3.48  static void create_aux_windows(_THIS)
    3.49  {
    3.50 @@ -438,6 +460,9 @@
    3.51  	/* Set the error handler if we lose the X display */
    3.52  	XIO_handler = pXSetIOErrorHandler(xio_errhandler);
    3.53  
    3.54 +	/* Set the X extension error handler */
    3.55 +	Xext_handler = pXSetExtensionErrorHandler(xext_errhandler);
    3.56 +
    3.57  	/* use default screen (from $DISPLAY) */
    3.58  	SDL_Screen = DefaultScreen(SDL_Display);
    3.59