huw@siesoft.co.uk (Huw Roberts) (03/21/91)
The following program gives the following protocol error and I can't work out why. Enlightenment would be greatly appreciated. A sensible mechanism for fixing it would also be appreciated. The protocol error: ------------------------------------------------------------------------------- X Error: BadMatch, invalid parameter attributes Request Major code 72 () Request Minor code ResourceID 0xe00002 Error Serial #13 Current Serial #14 ------------------------------------------------------------------------------- The code: ------------------------------------------------------------------------------- #include <stdio.h> #include <X11/Intrinsic.h> #include <X11/IntrinsicP.h> #include <X11/CoreP.h> #include <X11/Xatom.h> #include <Xm/DrawingA.h> int data[3][3] = { 0,1,0, 1,1,1, 0,1,0 }; Display *display; int rows=3, cols=3; main( argc, argv ) int argc; char *argv[]; { int row, col; Widget toplevel; XImage *mask; Screen *screen; Pixmap maskp; int n; Arg args[10]; extern char *pm_progname = argv[0]; toplevel = XtInitialize ("viewer", "Pgmtoxpm", NULL, NULL, &argc, argv); display = XtDisplay(toplevel); screen = XtScreen(toplevel); XSynchronize(display, True); mask = XCreateImage(display, DefaultVisualOfScreen(screen), 1, XYBitmap, 0, 0, ((cols>>3)+1)<<3, rows, 8, 0); mask->data = malloc((mask->bytes_per_line+100) * (rows+100)); /* Initialize. */ for ( row = 0; row < rows; row++) { for ( col = 0; col < cols; col++) XPutPixel(mask, col, row, data[row][col]); } maskp = XCreatePixmap(display, RootWindowOfScreen(screen), cols, rows, 1); XPutImage(display, maskp, DefaultGCOfScreen(screen), mask, 0, 0, 0, 0, cols, rows); } ------------------------------------------------------------------------------- Basically the problem is with the last statement. Note that both the Image and the Pixmap have depth 1. Huw P.S. Could you mail any replies because we tend to lose articles from comp.windows.x. Thanks -- If you want to flame, mail me directly and I'll summarise the best. Huw Roberts (huw@siesoft.co.uk) Siemens Plc., System Development Group, Woodley House, 65-73, Crockhamwell Road, Woodley, Reading, Berkshire, RG5 3JP England.
mouse@lightning.mcrcim.mcgill.EDU (der Mouse) (03/26/91)
> The following program gives the following protocol error and I can't > work out why. Enlightenment would be greatly appreciated. A > sensible mechanism for fixing it would also be appreciated. > X Error: BadMatch, invalid parameter attributes > Request Major code 72 () Major request 72 is PutImage, as one would expect. > mask = XCreateImage(display, DefaultVisualOfScreen(screen), > 1, XYBitmap, 0, 0, > ((cols>>3)+1)<<3, rows, 8, 0); > mask->data = malloc((mask->bytes_per_line+100) * (rows+100)); [...load mask's data...] > maskp = XCreatePixmap(display, RootWindowOfScreen(screen), cols, rows, 1); > XPutImage(display, maskp, DefaultGCOfScreen(screen), mask, 0, 0, 0, 0, > cols, rows); > Note that both the Image and the Pixmap have depth 1. Are you by any chance on a non-1-bit server? Because if so, the default GC of the screen will not be of depth 1, so a BadMatch is to be expected. If that's not the problem, something weird is going on. With four changes, it builds fine here, and runs fine on a monochrome server and dies as you describe on a color server. (The four changes: delete the #include of <Xm/DrawingA.h>, delete the extern from the declaration of pm_progname, add an extern declaration for malloc, and add calls to XCloseDisplay and exit at the end of main.) der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu
dmaustin@vivid.sun.com (Darren Austin) (03/27/91)
Hi Huw, I tried sending you mail, but I it bounced. In article <1991Mar21.083826.6036@siesoft.co.uk> huw@siesoft.co.uk (Huw Roberts) writes: > The protocol error: > ------------------------------------------------------------------------------- > X Error: BadMatch, invalid parameter attributes > Request Major code 72 () > Request Minor code > ResourceID 0xe00002 > Error Serial #13 > Current Serial #14 > ... > > maskp = XCreatePixmap(display, RootWindowOfScreen(screen), cols, rows, 1); > XPutImage(display, maskp, DefaultGCOfScreen(screen), mask, 0, 0, 0, 0, > cols, rows); > } > ------------------------------------------------------------------------------- > Basically the problem is with the last statement. Note that both the Image > and the Pixmap have depth 1. This is the problem. The pixmap and the image may both be of depth 1, but the DefaultDepth() of the server probably isn't. GC's can only be used with drawables of the same depth that it was created with. The DefaultGCOfScreen() is created with the RootWindow as the drawable (which is of depth DefaultDepth()). Therefore if your DefaultDepth() is something other than 1 (like it would be on a color display), you will get this BadMatch error. Now a solution would be to create your own GC with the pixmap as the drawable like so: gc = XCreateGC(display, pixmap, 0, NULL); This will give you the equivalent of the DefaultGC, except that you can use it with the pixmap. Hope this helps, --Darren -- Darren Austin | Actually, it's a buck and a quarter Windows and Graphics Software | staff, but I'm not going to tell Sun Microsystems, Mountain View | *him* that. dmaustin@sun.com |