changeset 1248:d2c6881935be

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.
author Ryan C. Gordon <icculus@icculus.org>
date Sat, 14 Jan 2006 08:15:38 +0000
parents ff73ee89ff4b
children e6a82dcdce09
files src/video/x11/SDL_x11dyn.h src/video/x11/SDL_x11sym.h src/video/x11/SDL_x11video.c
diffstat 3 files changed, 31 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/x11/SDL_x11dyn.h	Fri Jan 13 02:36:35 2006 +0000
+++ b/src/video/x11/SDL_x11dyn.h	Sat Jan 14 08:15:38 2006 +0000
@@ -57,6 +57,7 @@
 typedef Bool (*SDL_X11_XESetWireToEventRetType)(Display*,XEvent*,xEvent*);
 typedef int (*SDL_X11_XSynchronizeRetType)(Display*);
 typedef Status (*SDL_X11_XESetEventToWireRetType)(Display*,XEvent*,xEvent*);
+typedef int (*SDL_X11_XSetExtensionErrorHandlerType)(Display *,char *,char *);
 
 #define SDL_X11_SYM(req,ret,fn,params) extern ret (*p##fn) params;
 #include "SDL_x11sym.h"
--- a/src/video/x11/SDL_x11sym.h	Fri Jan 13 02:36:35 2006 +0000
+++ b/src/video/x11/SDL_x11sym.h	Sat Jan 14 08:15:38 2006 +0000
@@ -113,6 +113,8 @@
 SDL_X11_SYM(1,XExtDisplayInfo*,XextFindDisplay,(XExtensionInfo*,Display*))
 SDL_X11_SYM(1,int,XextRemoveDisplay,(XExtensionInfo*,Display*))
 SDL_X11_SYM(1,Bool,XQueryExtension,(Display*,_Xconst char*,int*,int*,int*))
+SDL_X11_SYM(1,char *,XDisplayString,(Display*))
+SDL_X11_SYM(1,int,XGetErrorText,(Display*,int,char*,int))
 
 #ifdef X_HAVE_UTF8_STRING
 SDL_X11_SYM(1,int,Xutf8TextListToTextProperty,(Display*,char**,int,XICCEncodingStyle,XTextProperty*))
@@ -159,6 +161,7 @@
 SDL_X11_SYM(1,SDL_X11_XSynchronizeRetType,XSynchronize,(Display*,Bool))
 SDL_X11_SYM(1,SDL_X11_XESetWireToEventRetType,XESetWireToEvent,(Display*,int,SDL_X11_XESetWireToEventRetType))
 SDL_X11_SYM(1,SDL_X11_XESetEventToWireRetType,XESetEventToWire,(Display*,int,SDL_X11_XESetEventToWireRetType))
+SDL_X11_SYM(1,SDL_X11_XSetExtensionErrorHandlerType,XSetExtensionErrorHandler,(SDL_X11_XSetExtensionErrorHandlerType))
 
 /* end of SDL_x11sym.h ... */
 
--- a/src/video/x11/SDL_x11video.c	Fri Jan 13 02:36:35 2006 +0000
+++ b/src/video/x11/SDL_x11video.c	Sat Jan 14 08:15:38 2006 +0000
@@ -220,7 +220,7 @@
 	       (e->error_code <= (vm_error+XF86VidModeNumberErrors)))) ) {
 #ifdef XFREE86_DEBUG
 { char errmsg[1024];
-  XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
+  pXGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
 printf("VidMode error: %s\n", errmsg);
 }
 #endif
@@ -235,7 +235,7 @@
 	      (e->error_code <= (dga_error+XF86DGANumberErrors))) ) {
 #ifdef XFREE86_DEBUG
 { char errmsg[1024];
-  XGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
+  pXGetErrorText(d, e->error_code, errmsg, sizeof(errmsg));
 printf("DGA error: %s\n", errmsg);
 }
 #endif
@@ -262,6 +262,28 @@
 	return(XIO_handler(d));
 }
 
+static int (*Xext_handler)(Display *,char *,char *) = NULL;
+static int xext_errhandler(Display *d, char *ext_name, char *reason)
+{
+#ifdef XFREE86_DEBUG
+	printf("Xext error inside SDL (may be harmless):\n");
+	printf("  Extension \"%s\" %s on display \"%s\".\n",
+	       ext_name, reason, pXDisplayString(d));
+#endif
+
+	if (strcmp(reason, "missing") == 0) {
+		/*
+		 * Since the query itself, elsewhere, can handle a missing extension
+		 *  and the default behaviour in Xlib is to write to stderr, which
+		 *  generates unnecessary bug reports, we just ignore these.
+		 */
+		return 0;
+	}
+
+	/* Everything else goes to the default handler... */
+	return Xext_handler(d, ext_name, reason);
+}
+
 /* Create auxiliary (toplevel) windows with the current visual */
 static void create_aux_windows(_THIS)
 {
@@ -438,6 +460,9 @@
 	/* Set the error handler if we lose the X display */
 	XIO_handler = pXSetIOErrorHandler(xio_errhandler);
 
+	/* Set the X extension error handler */
+	Xext_handler = pXSetExtensionErrorHandler(xext_errhandler);
+
 	/* use default screen (from $DISPLAY) */
 	SDL_Screen = DefaultScreen(SDL_Display);