@begin(header)
author: ackerman=ag@ics.uci.edu
show_author: ShowNone
author_organization: MIT
node_expert: ackerman=ag@ics.uci.edu 
expiration_date: 10/10/93
last_modifier: ackerman=ag@ics.uci.edu
last_mod_date: 10/10/91
mod_num: 1
@end(header)
---------------------
What to do about Bugs
---------------------

Unfortunately, debugging at the Xlib level is difficult because of
the lack of information that comes back from an error.  Normally,
all you get is a protocol error message (the print-out from the
default error handler for Xlib).

These protocol errors can be quite cryptic.  Moreover, because
of the asynchronous nature of X, they may not occur nearby the
code that caused them.  *Using printf's to debug X will not
work.*

To debug Xlib:

	1.  Debug in sychronous mode by including an
		XSynchronize call.  You can sychronize
		at specific calls with a XSync command.
	2.  If you use a debugging interpretor such as
		Saber-C, you can do an XFlush, which
		forces the Xlib buffers to the server.

		You can narrow in on the location of
		a protocol error by doing XFlush's at
		various points in your code.
	3.  Follow the mappings between protocol statements
		and Xlib calls.


Below is how to interpret one such X Protocol Error.  If this
information is not sufficient, please click on "I'm Unhappy"
below and ask for more information.

@begin(E)
X Protocol Errors

Protocol errors look like:

X Error of failed request:  BadDrawable (invalid Pixmap or Window 
parameter) 
  Major opcode of failed request:  55 (X_CreateGC) 
  Minor opcode of failed request:  0 
  Resource id in failed request:  0x0 
  Serial number of failed request:  5 
  Current serial number in output stream:  7 

If you are programming, look at the field called "resource id".  If
the value is "0x0", then you are sending a null value to the server
in a protocol request.  

In Xt, the typical error is sending the value from an XtWindow
call before your program has performed an XtRealizeWidget.  Since
windows for widgets are created at the XtRealizeWidget time, a
widget will not have a valid window id until then.  Hence, you
will get the NULL value from an XtWindow call before the widget
is realized.

In the above case, this is exactly what occurred.  The window id
provided to XCreateGC (which requires a window or pixmap id) was NULL.
@end(E)
