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

问题描述 投票:4回答:1

我刚开始在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进行编译。

c graphics xlib
1个回答
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()给我时间看!

© www.soinside.com 2019 - 2024. All rights reserved.