From 1e1cf6e89e14a93b0b9b8d7dfb047b78a2a803c3 Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Fri, 15 Oct 2010 07:09:07 +0000 Subject: [PATCH] Fix for Issue 129. --- Recast/Source/RecastRegion.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/Recast/Source/RecastRegion.cpp b/Recast/Source/RecastRegion.cpp index 5f19c76..6ad9fa5 100644 --- a/Recast/Source/RecastRegion.cpp +++ b/Recast/Source/RecastRegion.cpp @@ -991,11 +991,10 @@ bool rcBuildDistanceField(rcContext* ctx, rcCompactHeightfield& chf) return true; } -static void paintRectRegion(int minx, int maxx, int miny, int maxy, - unsigned short regId, +static void paintRectRegion(int minx, int maxx, int miny, int maxy, unsigned short regId, rcCompactHeightfield& chf, unsigned short* srcReg) { - const int w = chf.width; + const int w = chf.width; for (int y = miny; y < maxy; ++y) { for (int x = minx; x < maxx; ++x) @@ -1050,12 +1049,16 @@ bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf, // Mark border regions. - if (borderSize) + if (borderSize > 0) { - paintRectRegion(0, borderSize, 0, h, id|RC_BORDER_REG, chf, srcReg); id++; - paintRectRegion(w-borderSize, w, 0, h, id|RC_BORDER_REG, chf, srcReg); id++; - paintRectRegion(0, w, 0, borderSize, id|RC_BORDER_REG, chf, srcReg); id++; - paintRectRegion(0, w, h-borderSize, h, id|RC_BORDER_REG, chf, srcReg); id++; + // Make sure border will not overflow. + const int bw = rcMin(w, borderSize); + const int bh = rcMin(h, borderSize); + // Paint regions + paintRectRegion(0, bw, 0, h, id|RC_BORDER_REG, chf, srcReg); id++; + paintRectRegion(w-bw, w, 0, h, id|RC_BORDER_REG, chf, srcReg); id++; + paintRectRegion(0, w, 0, bh, id|RC_BORDER_REG, chf, srcReg); id++; + paintRectRegion(0, w, h-bh, h, id|RC_BORDER_REG, chf, srcReg); id++; } rcIntArray prev(256);