簡體   English   中英

如何解決Linux Graphics C程序中的以下錯誤?

[英]How do I solve the following error in Linux Graphics C program?

我正在嘗試編譯以下代碼,但是它給我一條錯誤消息,如下所示。 我是linux c圖形的初學者,無法弄清楚。 誰能提出解決方案?

碼:

#include<stdio.h>
#include<graphics.h>
void main()
{
      int gd = DETECT, gm;
      int dx, dy, p, end;
      float x1, x2, y1, y2, x, y;
      initgraph(&gd, &gm,NULL);
      printf("Enter Value of X1: ");
      scanf("%f", &x1);
      printf("Enter Value of Y1: ");
      scanf("%f", &y1);
      printf("Enter Value of X2: ");
      scanf("%f", &x2);
      printf("Enter Value of Y2: ");
      scanf("%f", &y2);

      dx = abs(x1 - x2);
      dy = abs(y1 - y2);

      p = 2 * dy - dx;
      if(x1 > x2)
      {
            x = x2;
            y = y2;
            end = x1;
      }
      else
      {
            x = x1;
            y = y1;
            end = x2;
      }
      putpixel(x, y, 10);
      while(x < end)
      {
            x = x + 1;
            if(p < 0)
            {
                  p = p + 2 * dy;
            }
            else
            {
                  y = y + 1;
                  p = p + 2 * (dy - dx);
            }
            putpixel(x, y, 10);
      }
      getch();
      closegraph();
}

錯誤信息:

meshramsd@ubuntu:~/libgraph-1.0.2$ ./b
[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.
b: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
[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.
b: ../../src/xcb_io.c:274: poll_for_event: Assertion `!xcb_xlib_threads_sequence_lost' failed.
Aborted (core dumped)

您可以嘗試使用似乎在Linux Mint上運行良好的libsvga我在Mac上的Virtualbox下運行Mint沒問題。

我安裝了以下軟件包:

sudo apt-get install svgalib-bin libsvga1 libsvga1-dev

然后,我將您的代碼入侵了以下代碼:

#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <vga.h>
#include<stdio.h>

void main()
{
   int dx, dy, p, end;

   /* detect the chipset and give up supervisor rights */
   if (vga_init() < 0)
        return EXIT_FAILURE;

   vga_setmode(G1024x768x256);  /* some low resolution dont work */ 
   vga_setcolor(14);         /* color of pixel */

   float x1, x2, y1, y2, x, y;
   x1=10;
   y1=40;
   x2=800;
   y2=500;

   dx = abs(x1 - x2);
   dy = abs(y1 - y2);

   p = 2 * dy - dx;
   if(x1 > x2)
   {
       x = x2;
       y = y2;
       end = x1;
   } else {
       x = x1;
       y = y1;
       end = x2;
   }
   vga_drawpixel(x, y);
   while(x < end){
      x = x + 1;
      if(p < 0)
      {
         p = p + 2 * dy;
      } else {
         y = y + 1;
         p = p + 2 * (dy - dx);
      }
      vga_drawpixel(x, y);
   }
   sleep(10);

   /* restore textmode and fall back to ordinary text console handling */
   vga_setmode(TEXT);

}

我這樣編譯:

gcc graphics.c -lvga -lm -o graphics

並運行:

sudo ./graphics

我得到了這個輸出-如果您想要其他顏色或大小,可以輕松地更改數字。

在此處輸入圖片說明

我在ubuntu 18.04上的c中執行圖形代碼時發現了此錯誤。 我進行了很多搜索,但是沒有找到滿意的答案。 最終,我讀了很多次此錯誤,並發現了第一行錯誤。

“ [xcb]處理隊列時未知的序列號”。

錯誤代碼

#include <stdio.h>
#include <graphics.h>

int main() {

int gd = DETECT,gm;

int x1,y1,x2,y2;
float step,dx,dy;

initgraph(&gd,&gm,NULL);  // I found Error here  Initialized Graph before standard input 
printf("enter the value of x1 and y1 : ");
scanf("%d %d",&x1,&y1);
printf("Enter the value of x2 and y2 : ");
scanf("%d %d",&x2,&y2);

dx=abs(x2-x1);
dy=abs(y2-y1);

if (dx >= dy)
    step=dx;
else
    step=dy;

dx=dx/step;
dy=dy/step;

int x=x1;
int y=y1;

int i=1;
while(i <= step)
{
    putpixel(x,y,5);
    x=x+dx;
    y=y+dy;
    i++;
    delay(100);
}
getchar();
closegraph();
return 0;
}

無錯誤代碼

#include <stdio.h>
#include <graphics.h>

int main() {
int gd = DETECT,gm;

int x1,y1,x2,y2;
float step,dx,dy;


printf("enter the value of x1 and y1 : ");
scanf("%d %d",&x1,&y1);
printf("Enter the value of x2 and y2 : ");
scanf("%d %d",&x2,&y2);

initgraph(&gd,&gm,NULL); //after correction I initialized graph after standard input

dx=abs(x2-x1);
dy=abs(y2-y1);

if (dx >= dy)
    step=dx;
else
    step=dy;

dx=dx/step;
dy=dy/step;

int x=x1;
int y=y1;

int i=1;
while(i <= step)
{
    putpixel(x,y,5);
    x=x+dx;
    y=y+dy;
    i++;
    delay(100);
}
getchar();
closegraph();
return 0;
}

成功執行后,我得到了所需的輸出 在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM