From c9c687fc7382f0f50cc36174332142805ee87a03 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 13 Oct 2024 14:39:52 +0200 Subject: [PATCH] Recast: add bounds check for sweepscan indices Only happens on extremely large and complex geometry. --- .../recast/Recast/Source/RecastRegion.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/thirdparty/recast/Recast/Source/RecastRegion.cpp b/src/thirdparty/recast/Recast/Source/RecastRegion.cpp index 5b28b806..331041d7 100644 --- a/src/thirdparty/recast/Recast/Source/RecastRegion.cpp +++ b/src/thirdparty/recast/Recast/Source/RecastRegion.cpp @@ -1425,6 +1425,15 @@ bool rcBuildRegionsMonotone(rcContext* ctx, rcCompactHeightfield& chf, if (!previd) { previd = rid++; + + // todo(amos): figure out why this happens on very complex and large + // input geometry. + if (previd >= nsweeps) + { + ctx->log(RC_LOG_ERROR, "rcBuildLayerRegions: Sweep index out of bounds: previd (%d), nsweeps (%d).", previd, nsweeps); + return false; + } + sweeps[previd].rid = previd; sweeps[previd].ns = 0; sweeps[previd].nei = 0; @@ -1734,6 +1743,15 @@ bool rcBuildLayerRegions(rcContext* ctx, rcCompactHeightfield& chf, if (!previd) { previd = rid++; + + // todo(amos): figure out why this happens on very complex and large + // input geometry. + if (previd >= nsweeps) + { + ctx->log(RC_LOG_ERROR, "rcBuildLayerRegions: Sweep index out of bounds: previd (%d), nsweeps (%d).", previd, nsweeps); + return false; + } + sweeps[previd].rid = previd; sweeps[previd].ns = 0; sweeps[previd].nei = 0;