I am observing a problem with OpenGL and Xlib functions on Linux. I have an application which creates windows and draws random curves on them. A single instance of this application works fine with any number of windows. However, if I launch 2 instances of this application, one on each core of a dual-core CPU(using setaffinity), I am observing that one window of each instance goes blank and does not draw, while all other windows of both the instances continue drawing the curves properly.
Following is the code snippet:
//To create each window:
dpy = XOpenDisplay( “:0” );
scrnum = DefaultScreen( dpy );
root = RootWindow( dpy, scrnum );
visinfo = glXChooseVisual( dpy, scrnum, attrib );
attr.background_pixel = 0;
attr.border_pixel = 0;
attr.colormap = XCreateColormap( dpy, root, visinfo->visual, AllocNone );
attr.event_mask = StructureNotifyMask;
mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
win = XCreateWindow( dpy, root, xpos, ypos, width, height,
0, visinfo->depth, InputOutput,
visinfo->visual, mask, &attr );
//Storing the information for each window head:
struct head *h = &Heads[NumHeads];
strcpy( h->DisplayName, name );
h->Dpy = dpy;
h->Win = win;
h->Context = ctx;
h->WinWidth = width;
h->WinHeight = height;
//Event Handling for the created windows (separate function called after creating all the windows):
for ( i = 0; ( ( i < NumHeads ) && ( nowTime < endTime ) ); i++ ) //for all the heads
{
h = &Heads[i];
while ( XPending( h->Dpy ) > 0 && ( nowTime < endTime ) )
{
XNextEvent( h->Dpy, &event );
if ( event.xany.window == h->Win )
{
switch ( event.type )
{
case ConfigureNotify:
Resize( h, event.xconfigure.width, event.xconfigure.height ); //resizes the window
break;
default:
break;
}
time( &nowTime );
}
}
if( Redraw( h ) == -1 ) //draws random curves
{
return -1;
}
time( &nowTime );
}
Tried handling Expose event as well, but that did not help. Moreover, the problem is reproducible only rarely.
Any help in this regard would be greatly appreciated.