problem getting line to paint on window when program is run a second time

Andrew Weiss thermalstrategy at
Thu Feb 22 21:40:36 PST 2007

   I'm not sure this is the right place to post this, if it's not, if you 
could direct me to someone that could help , that would be great.

   I am running the following program on my AMD64 box. the first time I run 
it, it brings up a window, and paints a line and the 2 pixels fine. When I 
run it again from the same window, it only brings up the window, with no 
line and no pixels. When I run it from gdb, it works fine every time. 

program x.c, compiled as: gcc x.c -L/usr/X11R6/lib64 -lX11 under Linux 10.1

#include <X11/Xlib.h>
#include <unistd.h>
#include <stdlib.h>

int main()
// Open the display
Display *dpy = XOpenDisplay(NULL);

// Get some colors
unsigned long blackColor = BlackPixel(dpy, DefaultScreen(dpy));
unsigned long whiteColor = WhitePixel(dpy, DefaultScreen(dpy));

// Create the window
Window w = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 256, 256,
  0, blackColor, whiteColor);

// We want to get MapNotify events
XSelectInput(dpy, w, StructureNotifyMask);

// "Map" the window (that is, make it appear on the screen)
XMapWindow(dpy, w);

// Create a "Graphics Context"
GC gc = XCreateGC(dpy, w, 0, NULL);

// Tell the GC we draw using the white color
XSetForeground(dpy, gc, blackColor);

// Wait for the MapNotify event
  XEvent e;
  XNextEvent(dpy, &e);
  if (e.type == MapNotify)

// Draw the line
XDrawLine(dpy, w, gc, 10, 60, 180, 20);
XDrawPoint(dpy, w, gc, 20, 20);
XDrawPoint(dpy, w, gc, 30, 30);

// Send the "DrawLine" request to the server

// Wait for 10 seconds

XFreeGC(dpy, gc);


Don’t miss your chance to WIN 10 hours of private jet travel from Microsoft® 
Office Live

More information about the xorg mailing list