Re: XPutImage() Seg Fault

2015-01-27 Thread Glynn Clements

Richard Overstreet wrote:

>  displaydata = (unsigned char *)calloc(ROWS*COLS*2, sizeof(unsigned char));
> 
>  
>  
> Picture=XCreateImage(Monitor,DefaultVisual(Monitor,0),
> DefaultDepth(Monitor,0),

Is the display depth actually 16 bpp? If it's 32 bpp, the XPutImage
call will try to copy twice as much data as you've allocated, which
may well result in a segfault.

-- 
Glynn Clements 
___
xorg@lists.x.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.x.org/mailman/listinfo/xorg
Your subscription address: %(user_address)s

XPutImage() Seg Fault

2015-01-26 Thread Richard Overstreet
Hello All,

I have a simple code which I'll paste below which I think should display
a black or blank 512x512 pixel image however it segfaults according to
GDB at XPutImage(). I can't find any documentation as to why this is
occurring and I am hoping someone my have some insight. This is my first
exposure to X so I'm not sure what is going wrong and the documentation
has not been very helpful. Here is the code:

#include 
#include 

main(int argc, char *argv[])
{
Display*Monitor;
WindowImageWindow;
GCImageGC;
XWindowAttributesAtts;
XImage*Picture;
intROWS,COLS;
unsigned char*displaydata;

/* ... */

 ROWS = COLS = 512;
 
Monitor=XOpenDisplay(NULL);
if (Monitor == NULL)
  {
  printf("Unable to open graphics display\n");
  exit(0);
  }

ImageWindow=XCreateSimpleWindow(Monitor,RootWindow(Monitor,0),
50,10,/* x,y on screen */
COLS,ROWS,/* width, height */
2, /* border width */
BlackPixel(Monitor,0),
WhitePixel(Monitor,0));

ImageGC=XCreateGC(Monitor,ImageWindow,0,NULL);

XMapWindow(Monitor,ImageWindow);
XFlush(Monitor);
while(1)
  {
  XGetWindowAttributes(Monitor,ImageWindow,&Atts);
  if (Atts.map_state == IsViewable /* 2 */)
break;
  }

 unsigned char *dispalydata;

 displaydata = (unsigned char *)calloc(ROWS*COLS*2, sizeof(unsigned char));

 
 
Picture=XCreateImage(Monitor,DefaultVisual(Monitor,0),
DefaultDepth(Monitor,0),
ZPixmap,/* format */
0,/* offset */
 (char*)displaydata,/* the data */
COLS,ROWS,/* size of the image data */
16,/* pixel quantum (8, 16 or 32) */
0);/* bytes per line (0 causes compute) */

XPutImage(Monitor,ImageWindow,ImageGC,Picture,
0,0,0,0,/* src x,y and dest x,y offsets */
COLS,ROWS);/* size of the image data */

XFlush(Monitor);
sleep(2);
XCloseDisplay(Monitor);
}


Thanks in advance to anyone who can help.

-Richard
___
xorg@lists.x.org: X.Org support
Archives: http://lists.freedesktop.org/archives/xorg
Info: http://lists.x.org/mailman/listinfo/xorg
Your subscription address: %(user_address)s