Skip to content

Commit

Permalink
#3488 Fix mesh header condition
Browse files Browse the repository at this point in the history
  • Loading branch information
akleshchev committed Feb 4, 2025
1 parent 7eb9dd3 commit 42fce46
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 20 deletions.
50 changes: 31 additions & 19 deletions indra/newview/llmeshrepository.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ LLMeshRepoThread::LLMeshRepoThread()
mHeaderMutex = new LLMutex();
mLoadedMutex = new LLMutex();
mPendingMutex = new LLMutex();
mSkinMapMutex = new LLMutex();
mSignal = new LLCondition();
mHttpRequest = new LLCore::HttpRequest;
mHttpOptions = LLCore::HttpOptions::ptr_t(new LLCore::HttpOptions);
Expand Down Expand Up @@ -902,19 +903,21 @@ LLMeshRepoThread::~LLMeshRepoThread()
}

delete mHttpRequest;
mHttpRequest = NULL;
mHttpRequest = nullptr;
delete mMutex;
mMutex = NULL;
mMutex = nullptr;
delete mHeaderMutex;
mHeaderMutex = NULL;
mHeaderMutex = nullptr;
delete mLoadedMutex;
mLoadedMutex = NULL;
mLoadedMutex = nullptr;
delete mPendingMutex;
mPendingMutex = NULL;
mPendingMutex = nullptr;
delete mSkinMapMutex;
mSkinMapMutex = nullptr;
delete mSignal;
mSignal = NULL;
mSignal = nullptr;
delete[] mDiskCacheBuffer;
mDiskCacheBuffer = NULL;
mDiskCacheBuffer = nullptr;
}

void LLMeshRepoThread::run()
Expand Down Expand Up @@ -1820,8 +1823,7 @@ bool LLMeshRepoThread::fetchMeshHeader(const LLVolumeParams& mesh_params)
}
U32 flags = 0;
memcpy(&flags, buffer + 2 * sizeof(U32), sizeof(U32));
// Todo: parse and pass flags, they are the reason for the preamble
if (headerReceived(mesh_params, buffer + CACHE_PREAMBLE_SIZE, bytes, flags) == MESH_OK)
if (headerReceived(mesh_params, buffer + CACHE_PREAMBLE_SIZE, bytes - CACHE_PREAMBLE_SIZE, flags) == MESH_OK)
{
LL_DEBUGS(LOG_MESH) << "Mesh/Cache: Mesh header for ID " << mesh_params.getSculptID() << " - was retrieved from the cache." << LL_ENDL;

Expand Down Expand Up @@ -1902,9 +1904,9 @@ bool LLMeshRepoThread::fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod)
S32 disk_ofset = offset + CACHE_PREAMBLE_SIZE;
//check cache for mesh asset
LLFileSystem file(mesh_id, LLAssetType::AT_MESH);
if (in_cache && file.getSize() >= disk_ofset + size)
if (in_cache && (file.getSize() >= disk_ofset + size))
{
U8* buffer = new(std::nothrow) U8[size];
U8* buffer = new(std::nothrow) U8[size]; // todo, make buffer thread local and read in thread?
if (!buffer)
{
LL_WARNS(LOG_MESH) << "Can't allocate memory for mesh " << mesh_id << " LOD " << lod << ", size: " << size << LL_ENDL;
Expand Down Expand Up @@ -1955,7 +1957,7 @@ bool LLMeshRepoThread::fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod)
LLMutexLock lock(gMeshRepo.mThread->mHeaderMutex);

auto header_it = gMeshRepo.mThread->mMeshHeader.find(mesh_id);
if (header_it == gMeshRepo.mThread->mMeshHeader.end())
if (header_it != gMeshRepo.mThread->mMeshHeader.end())
{
LLMeshHeader& header = header_it->second;
// for safety just mark everything as missing
Expand All @@ -1971,11 +1973,13 @@ bool LLMeshRepoThread::fetchMeshLOD(const LLVolumeParams& mesh_params, S32 lod)
}
}

S32 bytes = header_size + CACHE_PREAMBLE_SIZE;
LLFileSystem file(mesh_id, LLAssetType::AT_MESH, LLFileSystem::READ_WRITE);
if (file.getMaxSize() >= bytes)
if (header_size > 0)
{
write_preamble(file, header_size, header_flags);
LLFileSystem file(mesh_id, LLAssetType::AT_MESH, LLFileSystem::READ_WRITE);
if (file.getMaxSize() >= CACHE_PREAMBLE_SIZE)
{
write_preamble(file, header_size, header_flags);
}
}

{
Expand Down Expand Up @@ -2239,8 +2243,12 @@ EMeshProcessingResult LLMeshRepoThread::lodReceived(const LLVolumeParams& mesh_p
if (volume->getNumFaces() > 0)
{
// if we have a valid SkinInfo, cache per-joint bounding boxes for this LOD
LLMeshSkinInfo* skin_info = mSkinMap[mesh_params.getSculptID()];
if (skin_info && isAgentAvatarValid())
LLPointer<LLMeshSkinInfo> skin_info = nullptr;
{
LLMutexLock lock(mSkinMapMutex);
skin_info = mSkinMap[mesh_params.getSculptID()];
}
if (skin_info.notNull() && isAgentAvatarValid())
{
for (S32 i = 0; i < volume->getNumFaces(); ++i)
{
Expand Down Expand Up @@ -2305,7 +2313,10 @@ bool LLMeshRepoThread::skinInfoReceived(const LLUUID& mesh_id, U8* data, S32 dat

// copy the skin info for the background thread so we can use it
// to calculate per-joint bounding boxes when volumes are loaded
mSkinMap[mesh_id] = new LLMeshSkinInfo(*info);
{
LLMutexLock lock(mSkinMapMutex);
mSkinMap[mesh_id] = new LLMeshSkinInfo(*info);
}

{
// Move the LLPointer in to the skin info queue to avoid reference
Expand Down Expand Up @@ -4348,6 +4359,7 @@ void LLMeshRepository::notifyLoadedMeshes()
// erase from background thread
mThread->mWorkQueue.post([=]()
{
LLMutexLock(mThread->mSkinMapMutex);
mThread->mSkinMap.erase(id);
});
}
Expand Down
1 change: 1 addition & 0 deletions indra/newview/llmeshrepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ class LLMeshRepoThread : public LLThread
LLMutex* mHeaderMutex;
LLMutex* mLoadedMutex;
LLMutex* mPendingMutex;
LLMutex* mSkinMapMutex;
LLCondition* mSignal;

//map of known mesh headers
Expand Down
2 changes: 1 addition & 1 deletion indra/newview/llskinningutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ void LLSkinningUtil::updateRiggingInfo(const LLMeshSkinInfo* skin, LLVOAvatar *a
for (U32 k=0; k<4; ++k)
{
S32 joint_index = idx[k];
if (wght[k] > 0.2f && num_joints > joint_index)
if (wght[k] > 0.2f && num_joints > joint_index && num_joints > 0)
{
S32 joint_num = skin->mJointNums[joint_index];
if (joint_num >= 0 && joint_num < LL_CHARACTER_MAX_ANIMATED_JOINTS)
Expand Down

0 comments on commit 42fce46

Please sign in to comment.