Skip to content

Commit

Permalink
Catch X11 extension errors...since most of these are notifications th…
Browse files Browse the repository at this point in the history
…at 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.
  • Loading branch information
icculus committed Jan 14, 2006
1 parent 007b1cd commit 359851f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/video/x11/SDL_x11dyn.h
Expand Up @@ -57,6 +57,7 @@ extern "C" {
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"
Expand Down
3 changes: 3 additions & 0 deletions src/video/x11/SDL_x11sym.h
Expand Up @@ -113,6 +113,8 @@ SDL_X11_SYM(1,void,XextDestroyExtension,(XExtensionInfo*))
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*))
Expand Down Expand Up @@ -159,6 +161,7 @@ SDL_X11_SYM(1,Bool,XShmQueryExtension,(Display*))
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 ... */

29 changes: 27 additions & 2 deletions src/video/x11/SDL_x11video.c
Expand Up @@ -220,7 +220,7 @@ static int x_errhandler(Display *d, XErrorEvent *e)
(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
Expand All @@ -235,7 +235,7 @@ printf("VidMode error: %s\n", errmsg);
(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
Expand All @@ -262,6 +262,28 @@ static int xio_errhandler(Display *d)
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)
{
Expand Down Expand Up @@ -438,6 +460,9 @@ static int X11_VideoInit(_THIS, SDL_PixelFormat *vformat)
/* 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);

Expand Down

0 comments on commit 359851f

Please sign in to comment.