I have just started using Graphics in C, and I encountered this error while running a simple program that draws concentric circles:
user@user:~/Documents/C$ gcc circle.c -lX11 -lgraph
user@user:~/Documents/C$ ./a.out
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that. a.out: ../../src/xcb_io.c:274: poll_for_event:
Assertion '!xcb_xlib_threads_sequence_lost' failed.
Aborted (core dumped)
And:
[xcb] Unknown sequence number while processing queue
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that. a.out: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
I looked up some forums on the internet and they suggested that adding #include<X11/Xlib.h>
and calling XInitThreads()
in the beginning of main()
would solve the problem, But I still get the same error while running.
I've attached the code:
#include<stdio.h>
#include<graphics.h>
#include<X11/Xlib.h>
int main()
{
XInitThreads();
int gd=DETECT, gm,r,x;
initgraph(&gd,&gm,NULL);
setbkcolor(WHITE);
setcolor(BLACK);
for(r=10;r<100;r+=10)
{
circle(150,150,r);
}
scanf("%d",&x);
closegraph();
return 0;
}
I use Ubuntu 14.04 and GCC for compiling.
I added the following call before closegraph()
;
wait_for_char()
;
where:
void wait_for_char()
{
//Wait for a key press
int in = 0;
while (in == 0) {
in = getchar();
}
}
This solves the problem without having to call XInitThreads()
.
Don't ask me why. But I use the wait_for_key()
anyway to give me time to look!