Norm Dresner
2004-11-16 19:06:31 UTC
After much coaxing by some very knowledgeable people, I finally got my first
X-window program to start properly by putting a wait-loop for an
ExposureEvent immediately after the call to XMapWindow(). That worked fine
on my personal development system but when I got the program to the heavily
loaded test bench, the program didn't start. Putting checkpoint printf()
after each X-window call, I found that the program had passed through the
wait-loop and was hung in my own Refresh() function which (re)writes the
screen.
Here's extracted code -- not all declarations or error checking is shown --
and this program _does_ work perfectly both on my development system and on
the test bench when it's (more-or-less) idle. It only fails to initialize
properly when the test bench system is heavily loaded. I first found that
the program initialized properly when I single-stepped it through the
debugger (gdb) and eventually deduced that I could simulate that by
inserting a sleep() at the indicated line. Sleeping for only 2 seconds
wasn't sufficient and 3 seconds wasn't always enough either but the 4-second
sleep seemed to work all the time. Obviously I'm still missing something
and I'm hoping that some experienced X-window programmers will spot it.
I'd appreciate any suggestions.
TIA
Norm
display = XOpenDisplay(display_name);
win = create_simple_window(display, width, height, 0, 0);
XSelectInput( display , win , ExposureMask );
XMapWindow(display, win);
XFlush(display);
while( TRUE )
{
XEvent event;
XNextEvent( display , &event );
if( event.type == Expose )
break;
}
}
<== sleep(4) inserted here
gc = create_gc(display, win);
XSync(display, False);
XFlush( display );
<== program hangs here as described above
Refresh();
X-window program to start properly by putting a wait-loop for an
ExposureEvent immediately after the call to XMapWindow(). That worked fine
on my personal development system but when I got the program to the heavily
loaded test bench, the program didn't start. Putting checkpoint printf()
after each X-window call, I found that the program had passed through the
wait-loop and was hung in my own Refresh() function which (re)writes the
screen.
Here's extracted code -- not all declarations or error checking is shown --
and this program _does_ work perfectly both on my development system and on
the test bench when it's (more-or-less) idle. It only fails to initialize
properly when the test bench system is heavily loaded. I first found that
the program initialized properly when I single-stepped it through the
debugger (gdb) and eventually deduced that I could simulate that by
inserting a sleep() at the indicated line. Sleeping for only 2 seconds
wasn't sufficient and 3 seconds wasn't always enough either but the 4-second
sleep seemed to work all the time. Obviously I'm still missing something
and I'm hoping that some experienced X-window programmers will spot it.
I'd appreciate any suggestions.
TIA
Norm
display = XOpenDisplay(display_name);
win = create_simple_window(display, width, height, 0, 0);
XSelectInput( display , win , ExposureMask );
XMapWindow(display, win);
XFlush(display);
while( TRUE )
{
XEvent event;
XNextEvent( display , &event );
if( event.type == Expose )
break;
}
}
<== sleep(4) inserted here
gc = create_gc(display, win);
XSync(display, False);
XFlush( display );
<== program hangs here as described above
Refresh();