Merge pull request #169 from wbierman/master
Detect, log and fail in the event of an overflow of region ids in watershed partitioning
This commit is contained in:
commit
6ee79b25a8
@ -1575,6 +1575,13 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf,
|
|||||||
// Make sure border will not overflow.
|
// Make sure border will not overflow.
|
||||||
const int bw = rcMin(w, borderSize);
|
const int bw = rcMin(w, borderSize);
|
||||||
const int bh = rcMin(h, borderSize);
|
const int bh = rcMin(h, borderSize);
|
||||||
|
|
||||||
|
if (regionId > 0xFFFB)
|
||||||
|
{
|
||||||
|
ctx->log(RC_LOG_ERROR, "rcBuildRegions: Region ID overflow");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Paint regions
|
// Paint regions
|
||||||
paintRectRegion(0, bw, 0, h, regionId|RC_BORDER_REG, chf, srcReg); regionId++;
|
paintRectRegion(0, bw, 0, h, regionId|RC_BORDER_REG, chf, srcReg); regionId++;
|
||||||
paintRectRegion(w-bw, w, 0, h, regionId|RC_BORDER_REG, chf, srcReg); regionId++;
|
paintRectRegion(w-bw, w, 0, h, regionId|RC_BORDER_REG, chf, srcReg); regionId++;
|
||||||
@ -1622,7 +1629,15 @@ bool rcBuildRegions(rcContext* ctx, rcCompactHeightfield& chf,
|
|||||||
if (i >= 0 && srcReg[i] == 0)
|
if (i >= 0 && srcReg[i] == 0)
|
||||||
{
|
{
|
||||||
if (floodRegion(x, y, i, level, regionId, chf, srcReg, srcDist, stack))
|
if (floodRegion(x, y, i, level, regionId, chf, srcReg, srcDist, stack))
|
||||||
|
{
|
||||||
|
if (regionId == 0xFFFF)
|
||||||
|
{
|
||||||
|
ctx->log(RC_LOG_ERROR, "rcBuildRegions: Region ID overflow");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
regionId++;
|
regionId++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user