On Wed, 05 Apr 2000, Josu Onandia wrote:
Hi,
With the following code I get an Access Violation:
unsigned char pattern[2] = { 2, 2}; GrLineOption linestyle = { 15, 1, 2, pattern };
GrCustomLine(-2, 0, 1, 0, &linestyle);
I've followed the execution until the call to 'dashedsegment', but then I get a bit lost. What is clear is that when this function calls (*doseg), the variables 'start' and 'end' havenŽt been initialized.
Hi Josu,
looks like you found a bug in one of the most compicated parts of GRX.
Some years ago I rewrote the intersection function several time until it worked without overflow / underflow / division by zero / ... in the usual cases.
Your example doesnŽt look like a usual case but of course should give an access violation.
The problem is the while loop doesnŽt set start & end but reports actual state as ŽonŽ
This patch should prevent the access violation. I donŽt know if itŽs the right soloution for this problem but it doesnŽt break the linetest demo:
Hope it helps, Hartmut
*** drwcpoly.c.org Thu Apr 6 21:03:38 2000 --- drwcpoly.c Thu Apr 6 22:18:11 2000 *************** *** 231,237 **** int x,y,dx,dy; int error,erradd,errsub,count; int xinc1,xinc2,yinc1,yinc2; ! int start[2],end[2];
/* find the current starting segment for the pattern */ pos = (p->ppos %= p->plength); --- 231,237 ---- int x,y,dx,dy; int error,erradd,errsub,count; int xinc1,xinc2,yinc1,yinc2; ! int start[2],end[2], se_init;
/* find the current starting segment for the pattern */ pos = (p->ppos %= p->plength); *************** *** 267,275 **** --- 267,277 ---- yinc1 = yinc2; xinc1 = 0; } + se_init = 0; if(on) { start[0] = x; start[1] = y; + se_init = 1; } else { prev = NULL; *************** *** 279,284 **** --- 281,287 ---- if(on) { end[0] = x; end[1] = y; + se_init |= 2; } if((error -= errsub) < 0) { error += erradd; *************** *** 300,314 **** if ( !old_state && on && count > 0) { start[0] = x; start[1] = y; } else if ( old_state && !on) { (*doseg)(start,end,prev,NULL,p); prev = NULL; } /* else: zero length element(s), continue current segment */ } } ! if(on) (*doseg)(start,end,prev,next,p); p->on = on; }
--- 303,321 ---- if ( !old_state && on && count > 0) { start[0] = x; start[1] = y; + se_init = 1; } else if ( old_state && !on) { (*doseg)(start,end,prev,NULL,p); prev = NULL; + se_init = 0; } /* else: zero length element(s), continue current segment */ } } ! if(on && se_init==3) { ! (*doseg)(start,end,prev,next,p); ! } p->on = on; }