summaryrefslogtreecommitdiff
path: root/indra/llmath
diff options
context:
space:
mode:
authorDon Kjer <don@lindenlab.com>2012-11-28 23:46:06 +0000
committerDon Kjer <don@lindenlab.com>2012-11-28 23:46:06 +0000
commit96ef49df75c0248e4843f9a5b53f010b819d59f3 (patch)
tree9f542fae939073bbb39464500d3fd477d1ed5fe5 /indra/llmath
parentdc71cae16b9c49a1d6b4d4a888c3a574049fd087 (diff)
parente0432f98ee515f9777604aa784d28b63d2abfe40 (diff)
Automated merge
Diffstat (limited to 'indra/llmath')
-rw-r--r--indra/llmath/lloctree.h52
-rw-r--r--indra/llmath/llvolume.cpp19
-rw-r--r--indra/llmath/tests/alignment_test.cpp33
-rw-r--r--indra/llmath/v3color.h1
4 files changed, 55 insertions, 50 deletions
diff --git a/indra/llmath/lloctree.h b/indra/llmath/lloctree.h
index c3f6f7de2a..4ac1e55cfc 100644
--- a/indra/llmath/lloctree.h
+++ b/indra/llmath/lloctree.h
@@ -78,7 +78,7 @@ public:
typedef LLOctreeTraveler<T> oct_traveler;
typedef LLTreeTraveler<T> tree_traveler;
- typedef LLPointer<T>* element_list;
+ typedef std::vector<LLPointer<T> > element_list;
typedef LLPointer<T>* element_iter;
typedef const LLPointer<T>* const_element_iter;
typedef typename std::vector<LLTreeListener<T>*>::iterator tree_listener_iter;
@@ -106,8 +106,9 @@ public:
: mParent((oct_node*)parent),
mOctant(octant)
{
- mData = NULL;
- mDataEnd = NULL;
+ //always keep a NULL terminated list to avoid out of bounds exceptions in debug builds
+ mData.push_back(NULL);
+ mDataEnd = &mData[0];
mCenter = center;
mSize = size;
@@ -133,9 +134,9 @@ public:
mData[i] = NULL;
}
- free(mData);
- mData = NULL;
- mDataEnd = NULL;
+ mData.clear();
+ mData.push_back(NULL);
+ mDataEnd = &mData[0];
for (U32 i = 0; i < getChildCount(); i++)
{
@@ -239,9 +240,9 @@ public:
bool isEmpty() const { return mElementCount == 0; }
element_list& getData() { return mData; }
const element_list& getData() const { return mData; }
- element_iter getDataBegin() { return mData; }
+ element_iter getDataBegin() { return &mData[0]; }
element_iter getDataEnd() { return mDataEnd; }
- const_element_iter getDataBegin() const { return mData; }
+ const_element_iter getDataBegin() const { return &mData[0]; }
const_element_iter getDataEnd() const { return mDataEnd; }
U32 getChildCount() const { return mChildCount; }
@@ -321,14 +322,10 @@ public:
if ((getElementCount() < gOctreeMaxCapacity && contains(data->getBinRadius()) ||
(data->getBinRadius() > getSize()[0] && parent && parent->getElementCount() >= gOctreeMaxCapacity)))
{ //it belongs here
+ mData.push_back(NULL);
+ mData[mElementCount] = data;
mElementCount++;
- mData = (element_list) realloc(mData, sizeof(LLPointer<T>)*mElementCount);
-
- //avoid unref on uninitialized memory
- memset(mData+mElementCount-1, 0, sizeof(LLPointer<T>));
-
- mData[mElementCount-1] = data;
- mDataEnd = mData + mElementCount;
+ mDataEnd = &mData[mElementCount];
data->setBinIndex(mElementCount-1);
BaseType::insert(data);
return true;
@@ -364,14 +361,10 @@ public:
if( lt == 0x7 )
{
+ mData.push_back(NULL);
+ mData[mElementCount] = data;
mElementCount++;
- mData = (element_list) realloc(mData, sizeof(LLPointer<T>)*mElementCount);
-
- //avoid unref on uninitialized memory
- memset(mData+mElementCount-1, 0, sizeof(LLPointer<T>));
-
- mData[mElementCount-1] = data;
- mDataEnd = mData + mElementCount;
+ mDataEnd = &mData[mElementCount];
data->setBinIndex(mElementCount-1);
BaseType::insert(data);
return true;
@@ -436,16 +429,15 @@ public:
mData[i]->setBinIndex(i);
}
- mData[mElementCount] = NULL; //needed for unref
- mData = (element_list) realloc(mData, sizeof(LLPointer<T>)*mElementCount);
- mDataEnd = mData+mElementCount;
+ mData[mElementCount] = NULL;
+ mData.pop_back();
+ mDataEnd = &mData[mElementCount];
}
else
{
- mData[0] = NULL; //needed for unref
- free(mData);
- mData = NULL;
- mDataEnd = NULL;
+ mData.clear();
+ mData.push_back(NULL);
+ mDataEnd = &mData[0];
}
notifyRemoval(data);
@@ -491,7 +483,7 @@ public:
}
//node is now root
- llwarns << "!!! OCTREE REMOVING FACE BY ADDRESS, SEVERE PERFORMANCE PENALTY |||" << llendl;
+ llwarns << "!!! OCTREE REMOVING ELEMENT BY ADDRESS, SEVERE PERFORMANCE PENALTY |||" << llendl;
node->removeByAddress(data);
llassert(data->getBinIndex() == -1);
return true;
diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index 81c52d370b..95fd81fda0 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -6974,19 +6974,20 @@ void LLVolumeFace::pushVertex(const LLVector4a& pos, const LLVector4a& norm, con
{
S32 new_verts = mNumVertices+1;
S32 new_size = new_verts*16;
-// S32 old_size = mNumVertices*16;
+ S32 old_size = mNumVertices*16;
//positions
- mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_size);
+ mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_size, old_size);
ll_assert_aligned(mPositions,16);
//normals
- mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_size);
+ mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_size, old_size);
ll_assert_aligned(mNormals,16);
//tex coords
new_size = ((new_verts*8)+0xF) & ~0xF;
- mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, new_size);
+ old_size = ((mNumVertices*8)+0xF) & ~0xF;
+ mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, new_size, old_size);
ll_assert_aligned(mTexCoords,16);
@@ -7040,7 +7041,7 @@ void LLVolumeFace::pushIndex(const U16& idx)
S32 old_size = ((mNumIndices*2)+0xF) & ~0xF;
if (new_size != old_size)
{
- mIndices = (U16*) ll_aligned_realloc_16(mIndices, new_size);
+ mIndices = (U16*) ll_aligned_realloc_16(mIndices, new_size, old_size);
ll_assert_aligned(mIndices,16);
}
@@ -7082,11 +7083,11 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat
}
//allocate new buffer space
- mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_count*sizeof(LLVector4a));
+ mPositions = (LLVector4a*) ll_aligned_realloc_16(mPositions, new_count*sizeof(LLVector4a), mNumVertices*sizeof(LLVector4a));
ll_assert_aligned(mPositions, 16);
- mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_count*sizeof(LLVector4a));
+ mNormals = (LLVector4a*) ll_aligned_realloc_16(mNormals, new_count*sizeof(LLVector4a), mNumVertices*sizeof(LLVector4a));
ll_assert_aligned(mNormals, 16);
- mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, (new_count*sizeof(LLVector2)+0xF) & ~0xF);
+ mTexCoords = (LLVector2*) ll_aligned_realloc_16(mTexCoords, (new_count*sizeof(LLVector2)+0xF) & ~0xF, (mNumVertices*sizeof(LLVector2)+0xF) & ~0xF);
ll_assert_aligned(mTexCoords, 16);
mNumVertices = new_count;
@@ -7133,7 +7134,7 @@ void LLVolumeFace::appendFace(const LLVolumeFace& face, LLMatrix4& mat_in, LLMat
new_count = mNumIndices + face.mNumIndices;
//allocate new index buffer
- mIndices = (U16*) ll_aligned_realloc_16(mIndices, (new_count*sizeof(U16)+0xF) & ~0xF);
+ mIndices = (U16*) ll_aligned_realloc_16(mIndices, (new_count*sizeof(U16)+0xF) & ~0xF, (mNumIndices*sizeof(U16)+0xF) & ~0xF);
//get destination address into new index buffer
U16* dst_idx = mIndices+mNumIndices;
diff --git a/indra/llmath/tests/alignment_test.cpp b/indra/llmath/tests/alignment_test.cpp
index ac0c45ae6f..9105b1c1fd 100644
--- a/indra/llmath/tests/alignment_test.cpp
+++ b/indra/llmath/tests/alignment_test.cpp
@@ -34,16 +34,6 @@
#include "../llsimdmath.h"
#include "../llvector4a.h"
-void* operator new(size_t size)
-{
- return ll_aligned_malloc_16(size);
-}
-
-void operator delete(void *p)
-{
- ll_aligned_free_16(p);
-}
-
namespace tut
{
@@ -59,6 +49,27 @@ tut::alignment_test_t tut_alignment_test("LLAlignment");
LL_ALIGN_PREFIX(16)
class MyVector4a
{
+public:
+ void* operator new(size_t size)
+ {
+ return ll_aligned_malloc_16(size);
+ }
+
+ void operator delete(void *p)
+ {
+ ll_aligned_free_16(p);
+ }
+
+ void* operator new[](size_t count)
+ { // try to allocate count bytes for an array
+ return ll_aligned_malloc_16(count);
+ }
+
+ void operator delete[](void *p)
+ {
+ ll_aligned_free_16(p);
+ }
+
LLQuad mQ;
} LL_ALIGN_POSTFIX(16);
@@ -78,7 +89,7 @@ void alignment_test_object_t::test<1>()
align_ptr = ll_aligned_malloc_16(sizeof(MyVector4a));
ensure("ll_aligned_malloc_16 failed", is_aligned(align_ptr,16));
- align_ptr = ll_aligned_realloc_16(align_ptr,2*sizeof(MyVector4a));
+ align_ptr = ll_aligned_realloc_16(align_ptr,2*sizeof(MyVector4a), sizeof(MyVector4a));
ensure("ll_aligned_realloc_16 failed", is_aligned(align_ptr,16));
ll_aligned_free_16(align_ptr);
diff --git a/indra/llmath/v3color.h b/indra/llmath/v3color.h
index 56cb2ae73e..daf3a6857b 100644
--- a/indra/llmath/v3color.h
+++ b/indra/llmath/v3color.h
@@ -33,6 +33,7 @@ class LLVector4;
#include "llerror.h"
#include "llmath.h"
#include "llsd.h"
+#include <string.h>
// LLColor3 = |r g b|