1

So I've read a lot of answers regarding this and I haven't got a solution yet which is why I'm posting this question.

I'm using Ubuntu 14.04LTS and gcc 4.8.4 for compiling graphics programs in College. I'd much rather use OPENGL but it's not an option as of now. I run into this error everytime I execute my code and no matter what I do, the SDL window shuts down after a delay that may or may not correspond to the delay provided in the program.

This is my code :

#include <stdio.h>
#include <graphics.h>
#include <X11/Xlib.h>
#include <math.h>

int XInitThreads();
int main(int argc, char *argv[]) {
XInitThreads();

int gd = DETECT, gm; 
float yi, xi, xx, yy; 
initgraph(&gd, &gm, NULL);

yy = 80.0000;


    for(yi = 60.0000; yi <= 80.0000; yi+=1) {

        xi = pow((400 - ((yy - yi)*(yy - yi))), 0.5);

        putpixel((int)(200 + xi), (int)(280 - yi), WHITE);

        putpixel((int)(200 - xi), (int)(280 - yi), WHITE);

        putpixel((int)(200 + xi), (int)(120 + yi), WHITE);

        putpixel((int)(200 - xi), (int)(120 + yi), WHITE);

    }

delay(10000);
closegraph();
return 0;
}

and I run into this error :

[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. 2602stackoverflow: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.

I've tried using libX11 but it still gives me the same errors. I've also tried a program by another user that worked fine according to him C Graphics Library Error but it still gave me the same error after I modified it to remove conio.h and while the line does get drawn in the graphics window, it shuts down due to the above error. Please help me resolve this.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Swapneel Mehta
  • 55
  • 1
  • 2
  • 12
  • You mentioned SDL in the question, but I can't see any SDL initialization in your main() function. Also, bear in mind that "graphics.h" is a Windows-only interface that comes bundled with Borland C compilers, it's non-standard, and you won't get it running on Ubuntu. – ajxs Feb 26 '16 at 03:11
  • So the issue is I have to manually code every function in the program such as drawing a line, ellipse, bezier curve or a circle. I cannot use any pre-defined code. What library do you suggest I use in this case? Also could you give me an example of SDL initialization, I seem to be having difficulties understanding it. – Swapneel Mehta Mar 04 '16 at 02:16
  • I assume you're talking about libSDL, the graphics library. https://www.libsdl.org/ You'll need to set that up from here, a few helpful tutorials can be found here: http://www.willusher.io/pages/sdl2/ That should help you get started. – ajxs Mar 04 '16 at 09:09
  • Yes I'm talking about the same libSDL. I'll try using it for drawing my graphics functions. Hopefully, it addresses the issue. – Swapneel Mehta Mar 06 '16 at 14:29

0 Answers0