diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp index 1ebd42babd..7c6a5a46c4 100644 --- a/indra/llmath/llvolume.cpp +++ b/indra/llmath/llvolume.cpp @@ -2403,7 +2403,27 @@ bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size) LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD with code " << uzip_result << " , will probably fetch from sim again." << LL_ENDL; return false; } - +// Add non-allocating variants of of unpackVolumeFaces + return unpackVolumeFacesInternal(mdl); +} + +bool LLVolume::unpackVolumeFaces(U8* in_data, S32 size) +{ + //input stream is now pointing at a zlib compressed block of LLSD + //decompress block + LLSD mdl; + U32 uzip_result = LLUZipHelper::unzip_llsd(mdl, in_data, size); + if (uzip_result != LLUZipHelper::ZR_OK) + { + LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD with code " << uzip_result << " , will probably fetch from sim again." << LL_ENDL; + return false; + } + return unpackVolumeFacesInternal(mdl); +} + +bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl) +{ +// { U32 face_count = mdl.size(); diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h index c9b12a9e97..c745a202db 100644 --- a/indra/llmath/llvolume.h +++ b/indra/llmath/llvolume.h @@ -1099,7 +1099,13 @@ protected: void createVolumeFaces(); public: virtual bool unpackVolumeFaces(std::istream& is, S32 size); +// Add non-allocating variants of of unpackVolumeFaces + bool unpackVolumeFaces(U8* in_data, S32 size); +private: + bool unpackVolumeFacesInternal(const LLSD& mdl); +public: +// virtual void setMeshAssetLoaded(BOOL loaded); virtual BOOL isMeshAssetLoaded(); diff --git a/indra/newview/lldrawable.cpp b/indra/newview/lldrawable.cpp index 68d5c53b80..d7ebf28354 100644 --- a/indra/newview/lldrawable.cpp +++ b/indra/newview/lldrawable.cpp @@ -918,9 +918,15 @@ void LLDrawable::updateDistance(LLCamera& camera, bool force_update) // MAINT-7926 Handle volumes in an animated object as a special case // SL-937: add dynamic box handling for rigged mesh on regular avatars. //if (volume->getAvatar() && volume->getAvatar()->isControlAvatar()) - if (volume->getAvatar()) + // reduce recursive calls. + // if (volume->getAvatar()) + // { + // const LLVector3* av_box = volume->getAvatar()->getLastAnimExtents(); + LLVOAvatar* avatarp = volume->getAvatar(); + if (avatarp) { - const LLVector3* av_box = volume->getAvatar()->getLastAnimExtents(); + const LLVector3* av_box = avatarp->getLastAnimExtents(); + // LLVector3 cam_pos_from_agent = LLViewerCamera::getInstance()->getOrigin(); LLVector3 cam_to_box_offset = point_to_box_offset(cam_pos_from_agent, av_box); mDistanceWRTCamera = llmax(0.01f, ll_round(cam_to_box_offset.magVec(), 0.01f)); diff --git a/indra/newview/llmaterialmgr.cpp b/indra/newview/llmaterialmgr.cpp index 099fdadd86..f5218ee4c6 100644 --- a/indra/newview/llmaterialmgr.cpp +++ b/indra/newview/llmaterialmgr.cpp @@ -477,7 +477,10 @@ void LLMaterialMgr::onGetAllResponse(bool success, const LLSD& content, const LL std::istringstream content_stream(content_string); LLSD response_data; - U32 uzip_result = LLUZipHelper::unzip_llsd(response_data, content_stream, content_binary.size()); + // Use new variant unzip_llsd + // U32 uzip_result = LLUZipHelper::unzip_llsd(response_data, content_stream, content_binary.size()); + U32 uzip_result = LLUZipHelper::unzip_llsd(response_data, content_binary.data(), content_binary.size()); + // if (uzip_result != LLUZipHelper::ZR_OK) { LL_WARNS("Materials") << "Cannot unzip LLSD binary content: " << uzip_result << LL_ENDL; diff --git a/indra/newview/llmeshrepository.cpp b/indra/newview/llmeshrepository.cpp index fc9b5174d7..0f1dc1b1da 100644 --- a/indra/newview/llmeshrepository.cpp +++ b/indra/newview/llmeshrepository.cpp @@ -78,6 +78,10 @@ #include "llfloaterreg.h" #include "boost/lexical_cast.hpp" +// Reduce temporaries and copes in decoding mesh headers +#include +#include +// #ifndef LL_WINDOWS #include "netdb.h" @@ -1901,27 +1905,35 @@ EMeshProcessingResult LLMeshRepoThread::headerReceived(const LLVolumeParams& mes U32 header_size = 0; if (data_size > 0) { - std::istringstream stream; - try - { - std::string res_str((char*)data, data_size); + // Reduce temporaries and copes in decoding mesh headers + // std::istringstream stream; + // try + // { + // std::string res_str((char*)data, data_size); - std::string deprecated_header(""); + // std::string deprecated_header(""); - if (res_str.substr(0, deprecated_header.size()) == deprecated_header) - { - res_str = res_str.substr(deprecated_header.size() + 1, data_size); - header_size = deprecated_header.size() + 1; - } - data_size = res_str.size(); + // if (res_str.substr(0, deprecated_header.size()) == deprecated_header) + // { + // res_str = res_str.substr(deprecated_header.size() + 1, data_size); + // header_size = deprecated_header.size() + 1; + // } + // data_size = res_str.size(); - stream.str(res_str); - } - catch (std::bad_alloc&) - { - // out of memory, we won't be able to process this mesh - return MESH_OUT_OF_MEMORY; - } + // stream.str(res_str); + // } + // catch (std::bad_alloc&) + // { + // // out of memory, we won't be able to process this mesh + // return MESH_OUT_OF_MEMORY; + // } + U32 dsize = data_size; + char* result_ptr = strip_deprecated_header((char*)data, dsize, &header_size); + + data_size = dsize; + + boost::iostreams::stream stream(result_ptr, data_size); + // if (!LLSDSerialize::fromBinary(header, stream, data_size)) { @@ -1990,19 +2002,22 @@ EMeshProcessingResult LLMeshRepoThread::lodReceived(const LLVolumeParams& mesh_p } LLPointer volume = new LLVolume(mesh_params, LLVolumeLODGroup::getVolumeScaleFromDetail(lod)); - std::istringstream stream; - try - { - std::string mesh_string((char*)data, data_size); - stream.str(mesh_string); - } - catch (std::bad_alloc&) - { - // out of memory, we won't be able to process this mesh - return MESH_OUT_OF_MEMORY; - } + // Reduce temporaries and copes in decoding mesh headers + // std::istringstream stream; + // try + // { + // std::string mesh_string((char*)data, data_size); + // stream.str(mesh_string); + // } + // catch (std::bad_alloc&) + // { + // // out of memory, we won't be able to process this mesh + // return MESH_OUT_OF_MEMORY; + // } - if (volume->unpackVolumeFaces(stream, data_size)) + // if (volume->unpackVolumeFaces(stream, data_size)) + if (volume->unpackVolumeFaces(data, data_size)) + // { if (volume->getNumFaces() > 0) { @@ -2032,10 +2047,13 @@ bool LLMeshRepoThread::skinInfoReceived(const LLUUID& mesh_id, U8* data, S32 dat { try { - std::string res_str((char*)data, data_size); - std::istringstream stream(res_str); + // Reduce temporaries and copes in decoding mesh headers + // std::string res_str((char*)data, data_size); + // std::istringstream stream(res_str); - U32 uzip_result = LLUZipHelper::unzip_llsd(skin, stream, data_size); + // U32 uzip_result = LLUZipHelper::unzip_llsd(skin, stream, data_size); + U32 uzip_result = LLUZipHelper::unzip_llsd(skin, data, data_size); + // if (uzip_result != LLUZipHelper::ZR_OK) { LL_WARNS(LOG_MESH) << "Mesh skin info parse error. Not a valid mesh asset! ID: " << mesh_id @@ -2073,10 +2091,13 @@ bool LLMeshRepoThread::decompositionReceived(const LLUUID& mesh_id, U8* data, S3 { try { - std::string res_str((char*)data, data_size); - std::istringstream stream(res_str); + // Reduce temporaries and copes in decoding mesh headers + // std::string res_str((char*)data, data_size); + // std::istringstream stream(res_str); - U32 uzip_result = LLUZipHelper::unzip_llsd(decomp, stream, data_size); + // U32 uzip_result = LLUZipHelper::unzip_llsd(decomp, stream, data_size); + U32 uzip_result = LLUZipHelper::unzip_llsd(decomp, data, data_size); + // if (uzip_result != LLUZipHelper::ZR_OK) { LL_WARNS(LOG_MESH) << "Mesh decomposition parse error. Not a valid mesh asset! ID: " << mesh_id @@ -2085,7 +2106,7 @@ bool LLMeshRepoThread::decompositionReceived(const LLUUID& mesh_id, U8* data, S3 return false; } } - catch (std::bad_alloc&) + catch (const std::bad_alloc&) // const cos const! { LL_WARNS(LOG_MESH) << "Out of memory for mesh ID " << mesh_id << " of size: " << data_size << LL_ENDL; return false; @@ -2122,20 +2143,22 @@ EMeshProcessingResult LLMeshRepoThread::physicsShapeReceived(const LLUUID& mesh_ volume_params.setSculptID(mesh_id, LL_SCULPT_TYPE_MESH); LLPointer volume = new LLVolume(volume_params,0); - std::istringstream stream; - try - { - std::string mesh_string((char*)data, data_size); - stream.str(mesh_string); - } - catch (std::bad_alloc&) - { - // out of memory, we won't be able to process this mesh - delete d; - return MESH_OUT_OF_MEMORY; - } + // Reduce temporaries and copes in decoding mesh headers + // std::istringstream stream; + // try + // { + // std::string mesh_string((char*)data, data_size); + // stream.str(mesh_string); + // } + // catch (std::bad_alloc&) + // { + // // out of memory, we won't be able to process this mesh + // delete d; + // return MESH_OUT_OF_MEMORY; + // } - if (volume->unpackVolumeFaces(stream, data_size)) + // if (volume->unpackVolumeFaces(stream, data_size)) + if (volume->unpackVolumeFaces(data, data_size)) { //load volume faces into decomposition buffer S32 vertex_count = 0; diff --git a/indra/newview/llpathfindingnavmesh.cpp b/indra/newview/llpathfindingnavmesh.cpp index 0287c07f96..41976674a7 100644 --- a/indra/newview/llpathfindingnavmesh.cpp +++ b/indra/newview/llpathfindingnavmesh.cpp @@ -140,12 +140,17 @@ void LLPathfindingNavMesh::handleNavMeshResult(const LLSD &pContent, U32 pNavMes if ( pContent.has(NAVMESH_DATA_FIELD) ) { const LLSD::Binary &value = pContent.get(NAVMESH_DATA_FIELD).asBinary(); - unsigned int binSize = value.size(); - std::string newStr(reinterpret_cast(&value[0]), binSize); - std::istringstream streamdecomp( newStr ); + // Use new variants of unzip_llsd calls + // unsigned int binSize = value.size(); + // std::string newStr(reinterpret_cast(&value[0]), binSize); + // std::istringstream streamdecomp( newStr ); + // unsigned int decompBinSize = 0; bool valid = false; - U8* pUncompressedNavMeshContainer = unzip_llsdNavMesh( valid, decompBinSize, streamdecomp, binSize ) ; + // Use new variants of unzip_llsd calls + // U8* pUncompressedNavMeshContainer = unzip_llsdNavMesh( valid, decompBinSize, streamdecomp, binSize ) ; + U8* pUncompressedNavMeshContainer = unzip_llsdNavMesh( valid, decompBinSize, value.data(), value.size() ) ; + // if ( !valid ) { LL_WARNS() << "Unable to decompress the navmesh llsd." << LL_ENDL;