[comp.windows.x] R4 XDrawArc problems: draws too much

mouse@lightning.mcrcim.mcgill.EDU (01/24/91)

			  X Window System Bug Report
			    xbugs@expo.lcs.mit.edu


VERSION:
    R4

CLIENT MACHINE and OPERATING SYSTEM:
    Any (tested with Sun SPARCserver 470, but is not a client-side bug)

DISPLAY TYPE:
    Sun-3/60 1600x1280 bwtwo
    Sun SPARCstation SLC bwtwo
    Sun SPARCstation 1 cgthree

WINDOW MANAGER:
    any or none

AREA:
    server

SYNOPSIS:
    XDrawArc often draws too much, when called with certain arguments.
    In one case, other arguments produced a server crash.

DESCRIPTION:

    When asked to draw a 90-degree arc of a circle between northeast
    and northwest (ie, angle1=45*64=2880, angle2=90*64=5760, with width
    equal to height), XDrawArc often (perhaps slightly less than half
    the time) actually draws the arc from northeast all the way to west
    (as if angle2 were 135*64 instead of 90*64).  Whether this happens
    appears to depend on the radius of the arc (ie, the values of width
    and height).

    xscope reveals that the protocol values on the wire are correct,
    thus placing this squarely at the server's door.

REPEAT BY:

    Run this program.  Give it, for example, 0 1 150 as arguments.
    (The server crash mentioned above came from an ill-advised run with
    arguments -150 1 150.  This bothers me somewhat less, though it is,
    strictly speaking, just as much a bug.)

	#define X 100
	#define Y 100
	#define W 300
	#define H 300
	
	#include <stdio.h>
	#include <X11/X.h>
	#include <X11/Xlib.h>
	#include <X11/Xutil.h>
	#include <X11/Xatom.h>
	
	int argc;
	char **argv;
	
	Display *disp;
	Screen *scr;
	int width;
	int height;
	int depth;
	Window rootwin;
	
	GC wingc;
	Window win;
	
	unsigned long int white;
	unsigned long int black;
	
	int begin;
	int inc;
	#define end myend /* UNIX linker reserves "end" */
	int end;
	
	main(ac,av)
	int ac;
	char **av;
	{
	 unsigned long int attrmask;
	 unsigned long int gcvalmask;
	 XGCValues gcval;
	 XSetWindowAttributes attr;
	 XTextProperty wn_prop;
	 XTextProperty in_prop;
	 XSizeHints normal_hints;
	 XWMHints wm_hints;
	 XClassHint class_hints;
	 XEvent e;
	
	 if (ac != 4)
	  { fprintf(stderr,"Usage: %s begin-radius radius-increment end-radius\n",av[0]);
	    exit(1);
	  }
	 begin = atoi(av[1]);
	 inc = atoi(av[2]);
	 end = atoi(av[3]);
	 disp = XOpenDisplay((char *)0);
	 scr = XDefaultScreenOfDisplay(disp);
	 depth = XDefaultDepthOfScreen(scr);
	 rootwin = XRootWindowOfScreen(scr);
	 white = XWhitePixelOfScreen(scr);
	 black = XBlackPixelOfScreen(scr);
	 attrmask = 0;
	 attr.background_pixel = black;
	 attrmask |= CWBackPixel;
	 attr.border_pixel = white;
	 attrmask |= CWBorderPixel;
	 attr.backing_store = NotUseful;
	 attrmask |= CWBackingStore;
	 attr.event_mask = ExposureMask | ButtonPressMask;
	 attrmask |= CWEventMask;
	 win = XCreateWindow(disp,rootwin,X,Y,W,H,1,depth,InputOutput,CopyFromParent,attrmask,&attr);
	 /* isn't ICCCM boilerplate fun... :-( */
	 wn_prop.value = (unsigned char *) "bug-test";
	 wn_prop.encoding = XA_STRING;
	 wn_prop.format = 8;
	 wn_prop.nitems = strlen((char *)wn_prop.value);
	 in_prop.value = (unsigned char *) "bug-test";
	 in_prop.encoding = XA_STRING;
	 in_prop.format = 8;
	 in_prop.nitems = strlen((char *)in_prop.value);
	 normal_hints.flags = PPosition | PSize;
	 normal_hints.x = X;
	 normal_hints.y = Y;
	 normal_hints.width = W;
	 normal_hints.height = H;
	 wm_hints.flags = InputHint;
	 wm_hints.input = False;
	 class_hints.res_name = "bugtest";
	 class_hints.res_class = "BugTest";
	 XSetWMProperties(disp,win,&wn_prop,&in_prop,argv,argc,&normal_hints,&wm_hints,&class_hints);
	 XMapRaised(disp,win);
	 gcvalmask = 0;
	 gcval.foreground = white;
	 gcvalmask |= GCForeground;
	 gcval.background = black;
	 gcvalmask |= GCBackground;
	 wingc = XCreateGC(disp,win,gcvalmask,&gcval);
	 while (1)
	  { XNextEvent(disp,&e);
	    switch (e.type)
	     { case Expose:
		  redisp();
		  break;
	       case ButtonPress:
		  exit(0);
		  break;
	     }
	  }
	}
	
	redisp()
	{
	 int i;
	
	 for (i=begin;(inc<0)?(i>=end):(i<=end);i+=inc)
	  { XDrawArc(disp,win,wingc,(W/2)-i,(H/2)-i,i*2,i*2,45*64,90*64);
	  }
	}

SAMPLE FIX:
    No clue.  (I'm hoping the arc code has been or will be rewritten
    for R5, so this can be mostly ignored.)

					der Mouse

			old: mcgill-vision!mouse
			new: mouse@larry.mcrcim.mcgill.edu