I'm writing an applicaiton for gentoo linux and redhat linux, one of the funciton always crashes on the redhat machine
usleep(100000);
Display *display;
display = XOpenDisplay(NULL);
Window w;
int x,y,i;
unsigned m;
Window root = XDefaultRootWindow(display);
XQueryPointer(display,root,&root,&w,&x,&y,&i,&i,&m);
XImage *image;
sleep(1);
image = XGetImage(display,root,0,0,1366,768,AllPlanes,XYPixmap);
int pixel = XGetPixel(image,x,y);
printf("\\clr(%i,%i,%i){}\n",x,y,pixel);
XCloseDisplay(display);
This function always crashes with a segmentation fault on the rhel machine
running the progrma in gdb: Program received signal SIGSEGV, Segmentation fault. 0x000000369942cb48 in ?? () from /usr/lib64/libX11.so.6 Missing separate debuginfos, use: debuginfo-install atk-1.30.0-1.el6.x86_64 cairo-1.8.8-6.el6_6.x86_64 expat-2.0.1-11.el6_2.x86_64 fontconfig-2.8.0-5.el6.x86_64 freetype-2.3.11-15.el6_6.1.x86_64 gdk-pixbuf2-2.24.1-6.el6_7.x86_64 glib2-2.28.8-4.el6.x86_64 glibc-2.12-1.166.el6_7.1.x86_64 gtk2-2.24.23-6.el6.x86_64 libX11-1.6.0-6.el6.x86_64 libXau-1.0.6-4.el6.x86_64 libXcomposite-0.4.3-4.el6.x86_64 libXcursor-1.1.14-2.1.el6.x86_64 libXdamage-1.1.3-4.el6.x86_64 libXext-1.3.2-2.1.el6.x86_64 libXfixes-5.0.1-2.1.el6.x86_64 libXi-1.7.2-2.2.el6.x86_64 libXinerama-1.1.3-2.1.el6.x86_64 libXrandr-1.4.1-2.1.el6.x86_64 libXrender-0.9.8-2.1.el6.x86_64 libXtst-1.2.2-2.1.el6.x86_64 libpng-1.2.49-2.el6_7.x86_64 libselinux-2.0.94-5.8.el6.x86_64 libxcb-1.9.1-3.el6.x86_64 pango-1.28.1-10.el6.x86_64 pixman-0.32.4-4.el6.x86_64 zlib-1.2.3-29.el6.x86_64
unfortunately I cannot install any additional packages(or install from 3rd party repos) for the rhel machines
backtrace: (gdb) bt
0 0x000000369942cb48 in ?? () from /usr/lib64/libX11.so.6
1 0x00000000004048ce in main (argc=2, argv=0x7fffffffe148) at tat.c:92
line 92 is : int pixel = XGetPixel(image,x,y);
the application works fine if that line is removed
thanks
int
andunsigned long
are not the same, right? – LubaXOpenDisplay()
? – LubaNULL
as commented, the man page forXGetPixel
says The image must contain the x and y coordinates. Which you have not checked. – KorteXQueryPointer(display,root,&root,&w,&x,&y,&i,&i,&m);
and you're just blindly using the value returned byimage = XGetImage(display,root,0,0,1366,768,AllPlanes,XYPixmap);
. Either one of those calls could fail. – Salome