I am trying to get the following program running on my AMD64 box. It runs the first time fine, putting up a window with a line and 2 pixels. the second time I run it, it puts up the window, but no line and pixels. Also, when I run it from gdb, it runs correctly every time.
The program is x.c, this is how I'm compiling it:
gcc x.c -L/usr/X11R6/lib64 -lX11
#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
for(;
{
XEvent e;
XNextEvent(dpy, &e);
if (e.type == MapNotify)
break;
}
// 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
XFlush(dpy);
// Wait for 10 seconds
sleep(10);
XFreeGC(dpy, gc);
XCloseDisplay(dpy);
_exit(0);
}