Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!aplvax.jhuapl.edu!grobicki From: grobicki@aplvax.jhuapl.edu (Thomas A. Grobicki) Newsgroups: comp.windows.x Subject: Problem with XFlush() after XDraw call Message-ID: <4262@aplcen.apl.jhu.edu> Date: 6 Dec 89 23:39:03 GMT Sender: news@aplcen.apl.jhu.edu Reply-To: grobicki@aplvax.jhuapl.edu (Thomas A. Grobicki) Distribution: usa Organization: The Johns Hopkins University Applied Physics Laboratory Lines: 125 I've been working on some simple X programming using the book X WINDOW APPLICATIONS PROGRAMMING by E.F. Johnson and K. Reichard (MIS Press). I've gotten to chapter 2, test program 2 (main is below) and have found some curious behaviour. If I don't include the sleep() call after the draw commands but before the XFlush(), the lines and box do not appear in the window. To add to the mystery the sleep() call must be at least 3 for a Sun 3/60 running either MIT-X 11R3 or Sun OpenWindows or at least 1 for a VaxStation 3100 running DECWindows. All the subroutines including the draw commands are as simple as possible. The sleep() call can appear before the draw commands and the program still works. Since the authors did not include the sleep() call, I was wondering what might be happening. I added them when I noticed that the program would work without the sleep() when running dbx debugger using the step command. Any help on this problem would be appreciated. I can send the remainder of the program if this would help. =================== Example Below ============================== /* ** The test program. All this program does is pop up a window, ** draws 4 lines and a box in the middle, waits 15 seconds, then ** quits. ** */ /* ** Most every program that uses X will need to include ** Xlib.h -- which contains many definitions for X types ** and symbols. */ #ifdef VMS #include #else /* UNIX */ #include #endif extern Display *theDisplay; main() { Window theWindow, openWindow(); GC theGC; /* ** Set up our connection to X */ initX(); /* ** Get some info on the display and print it */ getXInfo(); /* ** Open a window */ theWindow = openWindow( 100, 100, /* -- x, y location */ 300, 300, /* -- width, height */ 0, /* -- This is NOT a pop-up */ &theGC ); /* -- Graphics Context */ /* ** Draw into the Window */ /* \ / ** ------ ** | | ** | | ** ------ ** / \ */ drawLine( theWindow, theGC, 10, 10, /* Starting loction in x,y */ 100, 100 ); /* Ending location in x,y */ drawLine( theWindow, theGC, 200, 100, 290, 10 ); drawLine( theWindow, theGC, 10,290,100,200 ); drawLine( theWindow, theGC, 290,290,200,200); drawRectangle( theWindow, theGC, 100, 100, /* Starting location in x,y */ 100, 100 ); /* width and height */ /* ** Send all output to the screen. */ /* Apparently returning from sleep() triggers the flush */ sleep(3); /* required for some reason */ XFlush( theDisplay ); /* ** Wait a while to be able to play with window. */ sleep( 15 ); /* ** Release X resources and connection */ XDestroyWindow( theDisplay, theWindow ); quitX(); } /* ** end of file. */