summaryrefslogtreecommitdiff
path: root/indra/llmath/llvolume.cpp
diff options
context:
space:
mode:
authorAndreyL ProductEngine <alihatskiy@productengine.com>2018-03-02 00:47:08 +0200
committerAndreyL ProductEngine <alihatskiy@productengine.com>2018-03-02 00:47:08 +0200
commitaf9069edbff9df73cd75753b696aabd1ae8769b5 (patch)
tree123661ba69903fccccb1501f97c05ce2c1c73411 /indra/llmath/llvolume.cpp
parent723e0b2e6bfa348e6270677b1745ad29311a19c1 (diff)
parentf8c76535a35aaf245e261357a59e977bac5b2501 (diff)
Merged in lindenlab/viewer-release
Diffstat (limited to 'indra/llmath/llvolume.cpp')
-rw-r--r--indra/llmath/llvolume.cpp66
1 files changed, 52 insertions, 14 deletions
diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index 8d5e9de76b..f6a0ba802c 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -2368,9 +2368,10 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
//input stream is now pointing at a zlib compressed block of LLSD
//decompress block
LLSD mdl;
- if (!unzip_llsd(mdl, is, size))
+ U32 uzip_result = LLUZipHelper::unzip_llsd(mdl, is, size);
+ if (uzip_result != LLUZipHelper::ZR_OK)
{
- LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD, will probably fetch from sim again." << LL_ENDL;
+ LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD with code " << uzip_result << " , will probably fetch from sim again." << LL_ENDL;
return false;
}
@@ -2677,11 +2678,17 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
}
}
}
+
+ if (!cacheOptimize())
+ {
+ // Out of memory?
+ LL_WARNS() << "Failed to optimize!" << LL_ENDL;
+ mVolumeFaces.clear();
+ return false;
+ }
mSculptLevel = 0; // success!
- cacheOptimize();
-
return true;
}
@@ -2713,12 +2720,16 @@ void LLVolume::copyVolumeFaces(const LLVolume* volume)
mSculptLevel = 0;
}
-void LLVolume::cacheOptimize()
+bool LLVolume::cacheOptimize()
{
for (S32 i = 0; i < mVolumeFaces.size(); ++i)
{
- mVolumeFaces[i].cacheOptimize();
+ if (!mVolumeFaces[i].cacheOptimize())
+ {
+ return false;
+ }
}
+ return true;
}
@@ -5174,7 +5185,7 @@ public:
};
-void LLVolumeFace::cacheOptimize()
+bool LLVolumeFace::cacheOptimize()
{ //optimize for vertex cache according to Forsyth method:
// http://home.comcast.net/~tom_forsyth/papers/fast_vert_cache_opt.html
@@ -5185,7 +5196,7 @@ void LLVolumeFace::cacheOptimize()
if (mNumVertices < 3)
{ //nothing to do
- return;
+ return true;
}
//mapping of vertices to triangles and indices
@@ -5194,8 +5205,16 @@ void LLVolumeFace::cacheOptimize()
//mapping of triangles do vertices
std::vector<LLVCacheTriangleData> triangle_data;
- triangle_data.resize(mNumIndices/3);
- vertex_data.resize(mNumVertices);
+ try
+ {
+ triangle_data.resize(mNumIndices / 3);
+ vertex_data.resize(mNumVertices);
+ }
+ catch (std::bad_alloc)
+ {
+ LL_WARNS("LLVOLUME") << "Resize failed" << LL_ENDL;
+ return false;
+ }
for (U32 i = 0; i < mNumIndices; i++)
{ //populate vertex data and triangle data arrays
@@ -5307,7 +5326,8 @@ void LLVolumeFace::cacheOptimize()
LLVector4a* pos = (LLVector4a*) ll_aligned_malloc<64>(sizeof(LLVector4a)*2*num_verts+size);
if (pos == NULL)
{
- LL_ERRS("LLVOLUME") << "Allocation of positions vector[" << sizeof(LLVector4a) * 2 * num_verts + size << "] failed. " << LL_ENDL;
+ LL_WARNS("LLVOLUME") << "Allocation of positions vector[" << sizeof(LLVector4a) * 2 * num_verts + size << "] failed. " << LL_ENDL;
+ return false;
}
LLVector4a* norm = pos + num_verts;
LLVector2* tc = (LLVector2*) (norm + num_verts);
@@ -5318,7 +5338,9 @@ void LLVolumeFace::cacheOptimize()
wght = (LLVector4a*)ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
if (wght == NULL)
{
- LL_ERRS("LLVOLUME") << "Allocation of weights[" << sizeof(LLVector4a) * num_verts << "] failed" << LL_ENDL;
+ ll_aligned_free<64>(pos);
+ LL_WARNS("LLVOLUME") << "Allocation of weights[" << sizeof(LLVector4a) * num_verts << "] failed" << LL_ENDL;
+ return false;
}
}
@@ -5328,13 +5350,28 @@ void LLVolumeFace::cacheOptimize()
binorm = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
if (binorm == NULL)
{
- LL_ERRS("LLVOLUME") << "Allocation of binormals[" << sizeof(LLVector4a)*num_verts << "] failed" << LL_ENDL;
+ ll_aligned_free<64>(pos);
+ ll_aligned_free_16(wght);
+ LL_WARNS("LLVOLUME") << "Allocation of binormals[" << sizeof(LLVector4a)*num_verts << "] failed" << LL_ENDL;
+ return false;
}
}
//allocate mapping of old indices to new indices
std::vector<S32> new_idx;
- new_idx.resize(mNumVertices, -1);
+
+ try
+ {
+ new_idx.resize(mNumVertices, -1);
+ }
+ catch (std::bad_alloc)
+ {
+ ll_aligned_free<64>(pos);
+ ll_aligned_free_16(wght);
+ ll_aligned_free_16(binorm);
+ LL_WARNS("LLVOLUME") << "Resize failed: " << mNumVertices << LL_ENDL;
+ return false;
+ }
S32 cur_idx = 0;
for (U32 i = 0; i < mNumIndices; ++i)
@@ -5380,6 +5417,7 @@ void LLVolumeFace::cacheOptimize()
//std::string result = llformat("ACMR pre/post: %.3f/%.3f -- %d triangles %d breaks", pre_acmr, post_acmr, mNumIndices/3, breaks);
//LL_INFOS() << result << LL_ENDL;
+ return true;
}
void LLVolumeFace::createOctree(F32 scaler, const LLVector4a& center, const LLVector4a& size)