From 5070ca9fc42057d3c2b3c050bd13c15cb96c151d Mon Sep 17 00:00:00 2001 From: Mikko Mononen Date: Sat, 10 Jul 2010 08:51:35 +0000 Subject: [PATCH] Fix for Issue 95:rcIntArray still using new/delete --- Recast/Include/RecastAlloc.h | 8 +++++--- Recast/Source/RecastAlloc.cpp | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Recast/Include/RecastAlloc.h b/Recast/Include/RecastAlloc.h index 20dfef1..9a31637 100644 --- a/Recast/Include/RecastAlloc.h +++ b/Recast/Include/RecastAlloc.h @@ -40,10 +40,12 @@ class rcIntArray { int* m_data; int m_size, m_cap; + inline rcIntArray(const rcIntArray&); + inline rcIntArray& operator=(const rcIntArray&); public: inline rcIntArray() : m_data(0), m_size(0), m_cap(0) {} - inline rcIntArray(int n) : m_data(0), m_size(0), m_cap(n) { m_data = new int[n]; } - inline ~rcIntArray() { delete [] m_data; } + inline rcIntArray(int n) : m_data(0), m_size(0), m_cap(0) { resize(n); } + inline ~rcIntArray() { rcFree(m_data); } void resize(int n); inline void push(int item) { resize(m_size+1); m_data[m_size-1] = item; } inline int pop() { if (m_size > 0) m_size--; return m_data[m_size]; } @@ -56,7 +58,7 @@ public: template class rcScopedDelete { T* ptr; - inline T* operator=(T* p) { /*ptr = p; return ptr;*/ } + inline T* operator=(T* p); public: inline rcScopedDelete() : ptr(0) {} inline rcScopedDelete(T* p) : ptr(p) {} diff --git a/Recast/Source/RecastAlloc.cpp b/Recast/Source/RecastAlloc.cpp index 71e347a..2c7396a 100644 --- a/Recast/Source/RecastAlloc.cpp +++ b/Recast/Source/RecastAlloc.cpp @@ -55,7 +55,7 @@ void rcIntArray::resize(int n) { if (n > m_cap) { - if (!m_cap) m_cap = 8; + if (!m_cap) m_cap = n; while (m_cap < n) m_cap *= 2; int* newData = (int*)rcAlloc(m_cap*sizeof(int), RC_ALLOC_TEMP); if (m_size && newData) memcpy(newData, m_data, m_size*sizeof(int));