Merge pull request #15 from axelrodR/master

bugfix: divPoly caused a stack overrun by producing an 8th point
This commit is contained in:
Mikko Mononen 2014-01-21 22:41:10 -08:00
commit e117234170

View File

@ -193,29 +193,40 @@ static void dividePoly(const float* in, int nin,
rcVcopy(out2 + n*3, out1 + m*3); rcVcopy(out2 + n*3, out1 + m*3);
m++; m++;
n++; n++;
} // add the i'th point to the right polygon. Do NOT add points that are on the dividing line
if (inb) // since these were already added above
if (d[i] > 0)
{ {
out1[m*3+0] = in[i*3+0]; rcVcopy(out1 + m*3, in + i*3);
out1[m*3+1] = in[i*3+1];
out1[m*3+2] = in[i*3+2];
m++; m++;
if (d[i] != 0) // not on the line }
else if (d[i] < 0)
{
rcVcopy(out2 + n*3, in + i*3);
n++;
}
}
else // same side
{
// add the i'th point to the right polygon. Addition is done even for points on the dividing line
if (d[i] >= 0)
{
rcVcopy(out1 + m*3, in + i*3);
m++;
if (d[i] != 0)
continue; continue;
} }
rcVcopy(out2 + n*3, in + i*3);
// i-th point is on the other half plane or on the line
out2[n*3+0] = in[i*3+0];
out2[n*3+1] = in[i*3+1];
out2[n*3+2] = in[i*3+2];
n++; n++;
} }
}
*nout1 = m; *nout1 = m;
*nout2 = n; *nout2 = n;
} }
static void rasterizeTri(const float* v0, const float* v1, const float* v2, static void rasterizeTri(const float* v0, const float* v1, const float* v2,
const unsigned char area, rcHeightfield& hf, const unsigned char area, rcHeightfield& hf,
const float* bmin, const float* bmax, const float* bmin, const float* bmax,