From 9b574984063404820ee75df09d42c1bf4ee7b780 Mon Sep 17 00:00:00 2001 From: axelrodR Date: Fri, 31 Jan 2014 00:08:23 +0200 Subject: [PATCH] fix: multiple node allocation had a bug --- Detour/Source/DetourNode.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Detour/Source/DetourNode.cpp b/Detour/Source/DetourNode.cpp index f1e121d..7892706 100644 --- a/Detour/Source/DetourNode.cpp +++ b/Detour/Source/DetourNode.cpp @@ -113,17 +113,15 @@ dtNode* dtNodePool::getNode(dtPolyRef id, int nExtra) return 0; // add to hash table - i = (dtNodeIndex)m_nodeCount; - m_next[i] = m_first[bucket]; - m_first[bucket] = i; + int n = (dtNodeIndex)m_nodeCount; + dtNode* ret = &m_nodes[n]; - dtNode* ret = &m_nodes[i]; - - for ( ; nExtra >= 0; --nExtra) + // add the nodes from last to first + for (int j=n+nExtra ; j>=n; --j) { - i = (dtNodeIndex)m_nodeCount; + i = (dtNodeIndex)j; m_nodeCount++; - + // Init node node = &m_nodes[i]; node->pidx = 0; @@ -131,8 +129,10 @@ dtNode* dtNodePool::getNode(dtPolyRef id, int nExtra) node->total = 0; node->id = id; node->flags = 0; - } + m_next[i] = m_first[bucket]; + m_first[bucket] = i; + } return ret; }