fix: multiple node allocation had a bug

This commit is contained in:
axelrodR 2014-01-31 00:08:23 +02:00
parent d2306cacdd
commit 9b57498406

View File

@ -113,15 +113,13 @@ dtNode* dtNodePool::getNode(dtPolyRef id, int nExtra)
return 0; return 0;
// add to hash table // add to hash table
i = (dtNodeIndex)m_nodeCount; int n = (dtNodeIndex)m_nodeCount;
m_next[i] = m_first[bucket]; dtNode* ret = &m_nodes[n];
m_first[bucket] = i;
dtNode* ret = &m_nodes[i]; // add the nodes from last to first
for (int j=n+nExtra ; j>=n; --j)
for ( ; nExtra >= 0; --nExtra)
{ {
i = (dtNodeIndex)m_nodeCount; i = (dtNodeIndex)j;
m_nodeCount++; m_nodeCount++;
// Init node // Init node
@ -131,8 +129,10 @@ dtNode* dtNodePool::getNode(dtPolyRef id, int nExtra)
node->total = 0; node->total = 0;
node->id = id; node->id = id;
node->flags = 0; node->flags = 0;
}
m_next[i] = m_first[bucket];
m_first[bucket] = i;
}
return ret; return ret;
} }