From c215fcb2207cdc3167787305d3c40b6dd90ab1c9 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Wed, 3 Jul 2024 10:45:44 +0200 Subject: [PATCH] Recast: fix incorrect reachability table buffer size calculation Reachability table buffers were way larger than they should be due to an incorrect calculation of the buffer size. This bug fix reduced NavMesh sizes significantly (worlds edge '_small' was 200mb, and is now 20mb after this patch). --- src/naveditor/Editor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/naveditor/Editor.cpp b/src/naveditor/Editor.cpp index d400c1dd..0dd59fce 100644 --- a/src/naveditor/Editor.cpp +++ b/src/naveditor/Editor.cpp @@ -439,7 +439,7 @@ void Editor::saveAll(std::string path, dtNavMesh* mesh) header.params.disjointPolyGroupCount = linkData.setCount; header.params.reachabilityTableCount = m_reachabilityTableCount; - header.params.reachabilityTableSize = ((header.params.disjointPolyGroupCount + 31) / 32) * header.params.disjointPolyGroupCount * 32; + header.params.reachabilityTableSize = (linkData.setCount - 1) * ((linkData.setCount + 31) / 32) + (linkData.setCount - 1) / 32; fwrite(&header, sizeof(NavMeshSetHeader), 1, fp); @@ -458,7 +458,7 @@ void Editor::saveAll(std::string path, dtNavMesh* mesh) fwrite(tile->data, tile->dataSize, 1, fp); } - std::vector reachability(tableSize, 0); + std::vector reachability(header.params.reachabilityTableSize, 0); for (int i = 0; i < linkData.setCount; i++) setReachable(reachability, linkData.setCount, i, i, true);