viewer#2071 Properly handle 'out of memory' for meshes

master
Andrey Kleshchev 2024-07-19 20:17:37 +03:00 committed by Andrey Kleshchev
parent 5d25504f83
commit c4ff0b4889
5 changed files with 90 additions and 12 deletions

View File

@ -2227,7 +2227,12 @@ bool LLKeyframeMotion::dumpToFile(const std::string& name)
}
S32 file_size = getFileSize();
U8* buffer = new U8[file_size];
U8* buffer = new(std::nothrow) U8[file_size];
if (!buffer)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Bad memory allocation for buffer, file: " << name << " " << file_size << LL_ENDL;
}
LL_DEBUGS("BVH") << "Dumping " << outfilename << LL_ENDL;
LLDataPackerBinaryBuffer dp(buffer, file_size);
@ -2435,7 +2440,12 @@ void LLKeyframeMotion::onLoadComplete(const LLUUID& asset_uuid,
LLFileSystem file(asset_uuid, type, LLFileSystem::READ);
S32 size = file.getSize();
U8* buffer = new U8[size];
U8* buffer = new(std::nothrow) U8[size];
if (!buffer)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Bad memory allocation for buffer of size: " << size << LL_ENDL;
}
file.read((U8*)buffer, size); /*Flawfinder: ignore*/
LL_DEBUGS("Animation") << "Loading keyframe data for: " << motionp->getName() << ":" << motionp->getID() << " (" << size << " bytes)" << LL_ENDL;

View File

@ -285,7 +285,12 @@ bool LLFloaterBvhPreview::postBuild()
// create data buffer for keyframe initialization
S32 buffer_size = loaderp->getOutputSize();
U8* buffer = new U8[buffer_size];
U8* buffer = new(std::nothrow) U8[buffer_size];
if (!buffer)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Bad memory allocation for buffer, size: " << buffer_size << LL_ENDL;
}
LLDataPackerBinaryBuffer dp(buffer, buffer_size);
@ -992,7 +997,12 @@ void LLFloaterBvhPreview::onBtnOK(void* userdata)
LLKeyframeMotion* motionp = (LLKeyframeMotion*)floaterp->mAnimPreview->getDummyAvatar()->findMotion(floaterp->mMotionID);
S32 file_size = motionp->getFileSize();
U8* buffer = new U8[file_size];
U8* buffer = new(std::nothrow) U8[file_size];
if (!buffer)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Bad memory allocation for buffer, size: " << file_size << LL_ENDL;
}
LLDataPackerBinaryBuffer dp(buffer, file_size);
if (motionp->serialize(dp))

View File

@ -1360,7 +1360,19 @@ bool LLMeshRepoThread::fetchMeshSkinInfo(const LLUUID& mesh_id, bool can_retry)
U8* buffer = new(std::nothrow) U8[size];
if (!buffer)
{
LL_WARNS(LOG_MESH) << "Failed to allocate memory for skin info, size: " << size << LL_ENDL;
// Not sure what size is reasonable for skin info,
// but if 20MB allocation failed, we definetely have issues
const S32 MAX_SIZE = 20 * 1024 * 1024; //20MB
if (size < MAX_SIZE)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Bad memory allocation for skin info, size: " << size << LL_ENDL;
}
else
{
// Ignore failures for anomalously large data
LL_WARNS(LOG_MESH) << "Failed to allocate memory for skin info, size: " << size << LL_ENDL;
}
return false;
}
LLMeshRepository::sCacheBytesRead += size;
@ -1473,7 +1485,19 @@ bool LLMeshRepoThread::fetchMeshDecomposition(const LLUUID& mesh_id)
U8* buffer = new(std::nothrow) U8[size];
if (!buffer)
{
LL_WARNS(LOG_MESH) << "Failed to allocate memory for mesh decomposition, size: " << size << LL_ENDL;
// Not sure what size is reasonable for decomposition
// but if 20MB allocation failed, we definetely have issues
const S32 MAX_SIZE = 20 * 1024 * 1024; //20MB
if (size < MAX_SIZE)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Failed to allocate memory for mesh decomposition, size: " << size << LL_ENDL;
}
else
{
// Ignore failures for anomalously large decompositiions
LL_WARNS(LOG_MESH) << "Failed to allocate memory for mesh decomposition, size: " << size << LL_ENDL;
}
return false;
}
LLMeshRepository::sCacheBytesRead += size;
@ -1575,7 +1599,19 @@ bool LLMeshRepoThread::fetchMeshPhysicsShape(const LLUUID& mesh_id)
U8* buffer = new(std::nothrow) U8[size];
if (!buffer)
{
LL_WARNS(LOG_MESH) << "Failed to allocate memory for physics shape, size: " << size << LL_ENDL;
// Not sure what size is reasonable for physcis
// but if 20MB allocation failed, we definetely have issues
const S32 MAX_SIZE = 20 * 1024 * 1024; //20MB
if (size < MAX_SIZE)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Failed to allocate memory for mesh decomposition, size: " << size << LL_ENDL;
}
else
{
// Ignore failures for anomalously large meshes
LL_WARNS(LOG_MESH) << "Failed to allocate memory for mesh decomposition, size: " << size << LL_ENDL;
}
return false;
}
file.read(buffer, size);
@ -1766,9 +1802,21 @@ bool LLMeshRepoThread::fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod,
U8* buffer = new(std::nothrow) U8[size];
if (!buffer)
{
LL_WARNS(LOG_MESH) << "Can't allocate memory for mesh " << mesh_id << " LOD " << lod << ", size: " << size << LL_ENDL;
// todo: for now it will result in indefinite constant retries, should result in timeout
// or in retry-count and disabling mesh. (but usually viewer is beyond saving at this point)
// Not sure what size is reasonable for a mesh,
// but if 20MB allocation failed, we definetely have issues
const S32 MAX_SIZE = 20 * 1024 * 1024; //20MB
if (size < MAX_SIZE)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Can't allocate memory for mesh " << mesh_id << " LOD " << lod << ", size: " << size << LL_ENDL;
}
else
{
// Ignore failures for anomalously large data
LL_WARNS(LOG_MESH) << "Can't allocate memory for mesh " << mesh_id << " LOD " << lod << ", size: " << size << LL_ENDL;
// todo: for now it will result in indefinite constant retries, should result in timeout
// or in retry-count and disabling mesh. (but usually viewer is beyond saving at this point)
}
return false;
}
LLMeshRepository::sCacheBytesRead += size;

View File

@ -479,7 +479,12 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile()
else
{
S32 size = LLAPRFile::size(getFileName());
U8* buffer = new U8[size];
U8* buffer = new(std::nothrow) U8[size];
if (!buffer)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Bad memory allocation for buffer, size: " << size << LL_ENDL;
}
S32 size_read = infile.read(buffer,size);
if (size_read != size)
{

View File

@ -1521,7 +1521,12 @@ U32 LLViewerObject::processUpdateMessage(LLMessageSystem *mesgsys,
S32 size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_ExtraParams);
if (size > 0)
{
U8 *buffer = new U8[size];
U8 *buffer = new(std::nothrow) U8[size];
if (!buffer)
{
LLError::LLUserWarningMsg::showOutOfMemory();
LL_ERRS() << "Bad memory allocation for buffer, size: " << size << LL_ENDL;
}
mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_ExtraParams, buffer, size, block_num);
LLDataPackerBinaryBuffer dp(buffer, size);