Program with graphics being aborted, even though XInitThreads was called
Asked Answered
I

1

9

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.

Intensity answered 20/6, 2015 at 11:0 Comment(2)
This might be helpful: cgit.freedesktop.org/xorg/lib/libX11/tree/src/xcb_io.c#n212 Ownership of the event queue (if your library uses XCB) is required, and is one possible reason for this error if other threads are holding it.Wileywilfong
You could try ignoring the error and simply entering the value your program takes as input (scanf), it worked for me. If your program doesn't take any input value then the answer by DrPaul should workSpry
H
5

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!

Hex answered 30/3, 2016 at 10:21 Comment(1)
Still didn't fix it for mePreconize

© 2022 - 2024 — McMap. All rights reserved.