gpt4 book ai didi

c - 带有图形的程序被中止,即使调用了 XInitThreads

转载 作者:太空狗 更新时间:2023-10-29 15:05:37 24 4
gpt4 key购买 nike

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

最佳答案

我在 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() 给我时间看!

关于c - 带有图形的程序被中止,即使调用了 XInitThreads,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30953210/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com