[GRASSLIST:5298] Re: d.rgb kills monitor in cygwin

Glynn Clements glynn.clements at virgin.net
Sat Jan 11 18:24:29 EST 2003


[CC'd to Mike]

Jeff D. Hamann wrote:

> I've recently upgraded to the generic version of grass on win32/cygwin (nice
> not to need two windowing systems on the desktop) but when I try to run the
> d.rgb command, the graphics monitor shuts down and I get nothing. I can
> display single coverages at a time using d.rast but i need to use d.rgb,
> unless there's a better way to do this....

I've located the bug. The libW11 version of XCreateImage() [1] fails
to set the bytes_per_line member of the XImage structure correctly. 
Consequently, XDRIVER doesn't allocate enough memory for the data,
resulting in memory corruption.

[1] in src/display/devices/windows/libW11/w32/xlib.c

Basically, the implementation overlooks the following section of the
XCreateImage() manpage:

       If you pass a zero value in bytes_per_line, Xlib
       assumes that the scanlines are contiguous in memory and
       calculates the value of bytes_per_line itself.

Could someone who has Cygwin and the GRASS source test the attached
patch? Rebooting into Windows is inconvenient for me right now.

-- 
Glynn Clements <glynn.clements at virgin.net>

-------------- next part --------------
Index: src/display/devices/windows/libW11/w32/xlib.c
===================================================================
RCS file: /grassrepository/grass/src/display/devices/windows/libW11/w32/xlib.c,v
retrieving revision 1.5
diff -u -r1.5 xlib.c
--- src/display/devices/windows/libW11/w32/xlib.c	5 May 2002 07:40:23 -0000	1.5
+++ src/display/devices/windows/libW11/w32/xlib.c	11 Jan 2003 23:25:34 -0000
@@ -1821,6 +1821,15 @@
     XImage *img = (XImage *) allocateMemory ( sizeof ( XImage ) );
     NT_debug ("XCreateImage\n");
     if (img) {
+#define ROUNDUP(nbytes, pad) ((((nbytes) + ((pad)-1)) / (pad)) * ((pad)>>3))
+        if (bytes_per_line == 0)
+        {
+            if (format == ZPixmap)
+                bytes_per_line = ROUNDUP(depth * width, bitmap_pad);
+            else
+                bytes_per_line = ROUNDUP(width + offset, bitmap_pad);
+        }
+
         img->depth = depth;
         img->format = format;
         img->xoffset = offset;


More information about the grass-user mailing list