Better handling of contour problems.

This commit is contained in:
Mikko Mononen
2010-02-12 10:25:28 +00:00
parent f6236c133d
commit 668484eb14
6 changed files with 548 additions and 152 deletions
+18 -4
View File
@@ -573,7 +573,7 @@ bool rcBuildContours(rcCompactHeightfield& chf,
cset.cs = chf.cs;
cset.ch = chf.ch;
const int maxContours = chf.maxRegions*2;
int maxContours = rcMax((int)chf.maxRegions, 8);
cset.conts = new rcContour[maxContours];
if (!cset.conts)
return false;
@@ -657,11 +657,25 @@ bool rcBuildContours(rcCompactHeightfield& chf,
// Create contour.
if (simplified.size()/4 >= 3)
{
if (cset.nconts > maxContours)
if (cset.nconts >= maxContours)
{
// Allocate more contours.
// This can happen when there are tiny holes in the heighfield.
const int oldMax = maxContours;
maxContours *= 2;
rcContour* newConts = new rcContour[maxContours];
for (int j = 0; j < cset.nconts; ++j)
{
newConts[j] = cset.conts[j];
// Reset source pointers to prevent data deletion.
cset.conts[j].verts = 0;
cset.conts[j].rverts = 0;
}
delete [] cset.conts;
cset.conts = newConts;
if (rcGetLog())
rcGetLog()->log(RC_LOG_ERROR, "rcBuildContours: Too many contours %d, max %d.", cset.nconts, maxContours);
return false;
rcGetLog()->log(RC_LOG_WARNING, "rcBuildContours: Expanding max contours from %d to %d.", oldMax, maxContours);
}
rcContour* cont = &cset.conts[cset.nconts++];