即使调用了XInitThreads,也会中止图形的程序

时间:2015-06-20 11:00:54

标签: c graphics xlib

我刚开始在C中使用Graphics,我在运行绘制同心圆的简单程序时遇到了这个错误:

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)

[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.

我在互联网上查找了一些论坛,他们建议在#include<X11/Xlib.h>的开头添加XInitThreads()并调用main()可以解决问题,但我仍然可以获得运行时出现相同的错误。

我附上了代码:

#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;
}

我使用Ubuntu 14.04和GCC进行编译。

1 个答案:

答案 0 :(得分:3)

我在closegraph();

之前添加了以下调用

wait_for_char();

其中:

void wait_for_char()
{

    //Wait for a key press
    int in = 0;

    while (in == 0) {
        in = getchar();
    }
}

这解决了问题,而无需致电XInitThreads()。 不要问我为什么。但无论如何我用wait_for_key()给我时间看!